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 = new PDO( ‘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