When using mysqli to replace mysql in PHP + mysql development, the following prompt is displayed:
Deprecated: mysql_connect (): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead;
For the development environment, Apach, PHP, and Mysql are independently installed without the integrated environment. the version is as follows:
PHP ?? 5.6.3;
MySql ?? 5.6.21-log;
Replace mysql with mysqli. the code is as follows.
Some original mysql code:
1 // connect to the database 2 $ connection = mysql_connect ("127.0.0.1: 3306", "root", "root") or die ("Can not connnect ". mysql_errno (); 3 4 // sets the encoding format to prevent garbled characters on the page. 5 // mysql_query ('set names utf8', $ connection ); 6 7 // select database 8 mysql_select_db ("my_wiki", $ connection); 9 10 // Query Database 11 $ SQL = "select * from category "; 12 $ result = mysql_query ($ SQL );
Corresponding mysqli code:
1 // connect to the database 2 $ connection = new mysqli ("172.25.5.79: 3306", "root", "root", "discuz"); 3 4 // Set the encoding format, prevent page display garbled 5 $ connection-> query ("set names utf8"); 6 7 // query database 8 $ SQL = "select * from category "; 9 $ result = $ connection-> query ($ SQL );