doukeng7426 2013-12-08 07:39
浏览 57
已采纳

mysqli vs mysql-mysqli的性能和用法很复杂

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?

  • 写回答

1条回答 默认 最新

  • dongsun2789 2013-12-08 07:46
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)