Home >Backend Development >PHP Tutorial >PHP prompt Deprecated: mysql_connect(): The mysql extension is deprecated solution, deprecated_PHP tutorial
The example in this article describes the solution to the PHP prompt Deprecated: mysql_connect(): The mysql extension is deprecated. This type of problem is often encountered in PHP program development. Share it with everyone for your reference. The specific solutions are 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 连接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; }
I hope this article will be helpful to everyone’s PHP programming design.
Reference answer: I can’t hear the sound of a rainbow appearing, and I can’t hear the sound of the sun setting.
Write error_reporting(E_ALL & ~E_DEPRECATED) at the top of php; ignore the error