PHP hint Deprecated:mysql_connect (): The solution of the MySQL extension is deprecated

Source: Internet
Author: User
Tags deprecated php database

This article mainly introduces PHP hint Deprecated:mysql_connect (): The MySQL extension is deprecated solution, is in the PHP database program development often encountered errors, the need for friends can refer to the following

This example describes PHP hint Deprecated:mysql_connect (): The MySQL extension is Deprecated solution, in the development of PHP programs often encounter such problems. Share to everyone for your reference, the specific solution is as follows:

Change the code below to Mysqli or PDO.

?
12345 function connectit () { global $CFG; mysql_connect($CFG[‘db_host‘], $CFG[‘db_user‘], $CFG[‘db_pass‘]) or die(mysql_error()); mysql_select_db($CFG[‘db_name‘]); }

Pdo:

?
1 $dbh= newPDO(‘mysql:host=localhost;dbname=test‘, $user, $pass);

Mysqli:

?
12345678910 $link = mysqli_connect(  ‘localhost‘, /* The host to connect to 连接MySQL地址 */  ‘user‘,   /* The user to connect as 连接MySQL用户名 */ ‘password‘, /* The password to use 连接MySQL密码 */ ‘world‘);  /* The default database to query 连接数据库名称*/if (!$link) {   printf("Can‘t connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());   exit; }

 

PHP hint Deprecated:mysql_connect (): The solution of the MySQL extension is deprecated

Related Article

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.