PHP prompts Deprecated: mysql_connect (): The mysql extension is deprecated solution, deprecated

Source: Internet
Author: User
Tags php mysql

PHP prompts Deprecated: mysql_connect (): The mysql extension is deprecated solution, deprecated

The example in this article describes The solution for PHP prompt Deprecated: mysql_connect (): The mysql extension is deprecated, which is often encountered in PHP program development. The solution is as follows:

Change the following code to mysqli or PDO.

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:

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); 

MYSQLI:

$ Link = mysqli_connect ('localhost',/* The host to connect to The MySQL address */'user ', /* The user to connect as connection MySQL user name */'Password',/* The password to use to connect to MySQL password */'World '); /* The default database to query Connection database name */if (! $ Link) {printf ("Can't connect to MySQL Server. Errorcode: % s", mysqli_connect_error (); exit ;}

I hope this article will help you with PHP programming.


Mysql_connect (): The mysql extension is deprecated

I can't hear the Rainbow or the sun.

How can I disable the function when I call the function of PHP MYSQL?

Write error_reporting (E_ALL & ~ at the top of php &~ E_DEPRECATED); ignore errors

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.