mysql_connect():不建议使用mysql扩展,以后将删除:使用mysqli或PDO代替 [英] mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

查看:283
本文介绍了mysql_connect():不建议使用mysql扩展,以后将删除:使用mysqli或PDO代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

An error occurred in script 'C:\xampp\htdocs\framework\connect.php' on line 13: 
mysql_connect(): The mysql extension is deprecated and will be removed in the future: use       mysqli or PDO instead 
Date/Time: 12-17-2013 15:10:43 

我该如何解决这个问题.我环顾四周,也许这是php版本问题,但仍然无法删除此错误消息.

how can i solved this problems. i have look around this maybe the php version problem but still can not delete this error message.

<?php

/* Database config */

$db_host        = 'localhost';
$db_user        = '~';
$db_pass        = '~';
$db_database    = 'banners'; 

/* End config */


$link = @mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB     connection');

mysql_set_charset('utf8');
mysql_select_db($db_database,$link);

?>

推荐答案

简而言之,您需要重写所有数据库连接和查询.

Simply put, you need to rewrite all of your database connections and queries.

您正在使用mysql_*函数,这些函数现在已被弃用,将来会从PHP中删除.因此,您需要开始使用MySQLi或PDO,就像错误通知警告您一样.

You are using mysql_* functions which are now deprecated and will be removed from PHP in the future. So you need to start using MySQLi or PDO instead, just as the error notice warned you.

使用PDO(无错误处理)的基本示例:

<?php
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');
$result = $db->exec("INSERT INTO table(firstname, lastname) VAULES('John', 'Doe')");
$insertId = $db->lastInsertId();
?>

使用MySQLi的基本示例(无错误处理):

$db = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
$result = $db->query("INSERT INTO table(firstname, lastname) VAULES('John', 'Doe')");

这是一个方便的小PDO教程,可以帮助您入门.还有很多其他内容,其中 PDO替代MySQLi .

Here's a handy little PDO tutorial to get you started. There are plenty of others, and ones about the PDO alternative, MySQLi.

这篇关于mysql_connect():不建议使用mysql扩展,以后将删除:使用mysqli或PDO代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆