Dimitri
Dimitri

Reputation: 453

Going from mysql to mysqli in a painless way

php is about to stop support for mysql functions, and there are lots of tools/recommendations for how to upgrade to upgrade to mysqli from mysql. I came up with this design, and I wonder if there are any issues that my solutions can have:

  1. Create a file called translate.php and require_once it in all php files that use any mysql functions.
  2. Create global variable in that file and call it $_CONN
  3. overwrite default mysql function with the following (using overwrite_function which is not shown here)

$_CONN;        
        mysql_query($q)
        {mysqli_query($_CONN,$q);}

        mysql_error()
        {mysqli_error($_CONN);}

        mysql_connect($h,$u,$p)
        {$_CONN=mysqli_connect($h,$u,$p);}

        mysql_fetch_assoc($r)
        {mysqli_fetch_assoc($r);}

        mysql_fetch_array($r)
        {mysqli_fetch_array($r);}

Are there any issues with my solution?

Upvotes: 1

Views: 110

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157870

To move from mysql to mysqli in a painless way you have to move towards PDO

Upvotes: 4

Related Questions