Up until recently I was using mysql
instead of mysqli
or POD but as PHP has announded that it will not support mysql
so i have decided to move to mysqli
. But I have read several blogs/article everyone says that for security purpose mysqli
is better than mysql
but performance wise mysql
is better. If you are planning for high traffic website, then this small difference in performance may cause problem. Apart from this performance issue I have found that mysqli
and PDO is little complicated to use. For example for select function we can directly use this in my sql:
$res = mysql_query("SELECT * FROM `summary` WHERE id='35' limit 1");
$row = mysql_fetch_array($res);
But in mysqli
we have to use this something very complicated query for select/update/delete/insert etc. Is there any way i can use almost similar code for mysqli as well?
If you are planning for high traffic website, then this small difference in performance may cause problem.
Have you actually tested this out with your code? In many cases it is a negligible difference at best. So I would not worry. Typically these dire warnings of speed differences mean that something that took 1.5 seconds to complete would now take 1.6 seconds.
Besides, PDO adapters are simply the future. That is why they allow for prepared statements via ORM (object-relational mapping) or straight queries (see the example below).
But in mysqli we have to use this something very complicated query for select/update/delete/insert etc. Is there any way I can use almost similar code for mysqli as well?
Yes, you can. mysqli
has the capabilities to allow you to use pure MySQL queries without using PDO structure:
$db = new mysqli('localhost', 'user', 'pass', 'demo');
$result = $db->query("SELECT * FROM `summary` WHERE id='35' limit 1");
while($row = $result->fetch_assoc()){
echo '<pre>';
print_r($row);
echo '</pre>';
}
Also, if you are truly worried about MySQL performance, then just run a script like this MySQL Tuning Primer
script regularly to performance tune your MySQL install. That will do more to improve performance than obsessing over mysql
versus mysqli
in PHP.