Use mysqli to replace mysql in PHP development

Source: Internet
Author: User
Tags mysql code
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.