How to change mysql to mysqli?

前端 未结 11 1898
余生分开走
余生分开走 2020-11-21 04:55

Based on this code below I use for regular mysql, how could I convert it to use mysqli?

Is it as simple as changing mysql_query($sql); to

11条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 05:36

    2020+ Answer

    I've created a tool called Rector, that handles instant upgrades. There is also mysql → mysqli set.

    It handles:

    • function renaming
    • constant renaming
    • switched arguments
    • non-1:1 function calls changes, e.g.

      $data = mysql_db_name($result, $row);
      

      mysqli_data_seek($result, $row);
      $fetch = mysql_fetch_row($result);
      $data = $fetch[0];
      

    Just use it on your code:

    composer require rector/rector --dev
    vendor/bin/rector process src --set mysql-to-mysqli
    


    I've already run it on 2 big PHP projects and it works perfectly.

提交回复
热议问题