/    Sign up×
Community /Pin to ProfileBookmark

mysql_real_escape_string help!!

hi,
There is a php function mysql_real_escape_string() that we can use to clean string variable before put in to sql query. I am afraid is there any other that can I use with Integer types or the same I should use for all type? Can any one explain this please..

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiMay 26.2009 — Escaping something other than a string is not possible, there is no such thing as escaping an integer. If you want to clean/validate integers, you can either just cast to int to be sure of the type:

[code=php]$foo = (int) $foo;[/code]

or else check it is int and do soemthing different if it is not:

[code=php]if (!is_int($foo) {
// not an int
}[/code]
Copy linkTweet thisAlerts:
@firebladeauthorMay 26.2009 — thanks,

btw, I think I could not explain the question correctly. I want this..

[code=php]
$sql = "INSERT INTO %s(id, agg_number, app_date, inv_number, account_type, status) VALUES (%d, '%s', '%s', '%s', '%d', '%s')";
$sql = sprintf($sql, $this->tableName,
$this->id,
$this->agg_number,
$this->getApp_date())
$this->getInv_number(),
mysql_real_escape_string($this->getAccount_type()),
mysql_real_escape_string($this->getStatus()));
[/code]


This function is escaping the given data for string type and prapare it for insertion. So we can insert this data in to any mysql String Types. Same like there are Numeric Types and Date & Time Types. You might have looked in ADO.NET, there is parameter collection where we can define the data as DBTYPE.INT, DBTYPE.BIT so on before insertion. I was guessing is there any function that can do this job.
Copy linkTweet thisAlerts:
@MindzaiMay 26.2009 — If I'm understanding correctly, you can cast a variable to any type:

[code=php](int) $foo;

(bool) $foo;

(string) $foo;

[/code]

etc, although PHP is a loosely typed language and as a rule this is not usually necessary.
Copy linkTweet thisAlerts:
@firebladeauthorMay 26.2009 — Yes mindzai. That is what I wanted to confirm whether is there any other option or to go as usual. thanks for your replies.
×

Success!

Help @fireblade spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...