Jump to content

Very Confused


downah

Recommended Posts

So just seen this http://www.ultramegatech.com/2009/07/using-mysql-prepared-statements-in-php/ from another topic, and am a bit confused now, I started coding a little while back, but did not get introduced to mysqli until very recently, should I change all my normal mysql queries to the mysqli prepared statements like in the website/tutorial stated? does this mean I won't have to use mysql_real_escape_string and it is more secure in general?

 

Would really like some input, much appreciated.

Link to comment
Share on other sites

I have the same question, I have always used MySQL but now i'm hearing I should be using MySQLi?

If so, why? What is so much better about this versus the old MySQL? I am simply curious.

 

Thank you

Link to comment
Share on other sites

You don't have to change your queries to prepared statements, but there are benefits from doing so. Of course, there are also downsides -- prepared statements usually require a little more processing time, albeit very little (probably un-noticable).

 

If you use prepared statements, you do not have to escape data. SQL injection is all-together avoided. You do, however, still need to sanitize for things like XSS (if you prefer to store cleansed data rather than cleanse on output).

 

I have the same question, I have always used MySQL but now i'm hearing I should be using MySQLi?

If so, why? What is so much better about this versus the old MySQL? I am simply curious.

 

Thank you

 

The mysqli extension has quite a few benefits. Namely: Optional object-oriented API, prepared statements, it is being actively developed (the mysql extension is maintenance-only).

Link to comment
Share on other sites

I see so if I start using the mysqli functions I won't have to be sanitize my normal queries at all?, I understand why it is a little bit slower, but that does not really bother me, as the pro side of not having to sanitize the database input, and it being a lot more secure is a massive upside to me, I am just not sure what I am thinking is right.

 

Would you say a experienced developer being up to date would always use mysqli prepared statements instead of normal mysql queries? I am a bit confused as of what I should get used to doing, I was quite happy having gotten the grasp of the mysql functions  :shrug:

Link to comment
Share on other sites

@scootstah Thank you very much for explaining that.

 

I was quite happy having gotten the grasp of the mysql functions

I agree, but if mysqli is better I'll be glad to use it. It gives me a reason to make new stuff and play with my old code.
Link to comment
Share on other sites

Most up-to-date developers would be using PDO, unless there's some MySQL-specific syntax or optimizations that needed to be performed.

 

If I was writing MySQL-specific queries, I would use MySQLi in it's object oriented form. I tend to not use prepared statements, but they do have merits. If you don't care to sanitize beyond real_escape_string(), then it's great. Personally, I like stricter sanitization that I code myself, and feedback if x data doesn't match y format.

 

Only prepared statements, using placeholders, takes care of sanitization for you. The standard mysqli_query will not.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.