Jump to content
MakeWebGames

Question about MRES/general query optimization


Recommended Posts

Posted

So, I know security is incredibly important, so I've been attempting to read up on some things, and trying to affix some kind of security on any and all queries I type up, whether they're an obvious choice or not, for practice.

Take this example:

 

$csql = sprintf("SELECT u.userid,u.location,c.cityid,c.cityname FROM users u LEFT JOIN cities c ON u.location=c.cityid WHERE u.userid=$userid",mysql_real_escape_string($userid));
$cities = mysql_query($csql);
$c = mysql_fetch_array($cities);

 

Is this the correct way to go about using MRES? Or, am I way off?

Also wondering about the optimization side of things. When changing, say, the

u.*

You just add in the values you're going to use in your variable for the array, correct? (Per the example above)

I apologize in advance if this makes me sound absolutely retarded. But these are real questions I have, as I know, basically, nothing about security at the moment.

Posted
For starters why the sprintf when your not actually then using formatting in the query.

I just caught that. Should be more like this, right?

$csql = sprintf("SELECT u.userid,u.location,c.cityid,c.cityname FROM users u LEFT JOIN cities c ON u.location=c.cityid WHERE u.userid=%s",mysql_real_escape_string($userid  ));
$cities = mysql_query($csql);
$c = mysql_fetch_array($cities);
Posted

I would go read on sprintf and its formatting your incorrect there.

Also mres is used for strings not numbers which your query is dealing with. You would only need to filter the number.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...