php 5个版本,5.2、5.3、5.4、5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in,看意思就很明了,说mysql_connect这个模块将在未来弃用,请你使用mysqli或者PDO来替代。
解决方法1:
禁止php报错文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/
display_errors = On 改为 display_errors = Off
鉴于这个服务器都是给用户用的,有时候他们需要报错(...都是给朋友用的,^_^),不能这做,让他们改程序吧,看方案2.文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/
解决方法2:
常用的php语法连接mysql如下文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/
<?php $link = mysql_connect('localhost', 'user', 'password'); mysql_select_db('dbname', $link); 改成mysqi <?php $link = mysqli_connect('localhost', 'user', 'password', 'dbname');
常用mysql建表SQL如下文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/
<?php // 老的 mysql_query('CREATE TEMPORARY TABLE `table`', $link); // 新的 mysqli_query($link, 'CREATE TEMPORARY TABLE `table`');
解决方法三:
在php程序代码里面设置报警级别文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/
<?php error_reporting(E_ALL ^ E_DEPRECATED);
Deprecated的问题就这样解决掉了,不过还是建议大家尽快取消mysql的用法,全部都走向mysqli或者mysqlnd等等。mysql确实是太不安全而且太老旧了。文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/
文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/文章源自运维生存时间-https://www.ttlsa.com/php/deprecated-mysql-connect/
12F
:sad: 现在刚开始学PHP,总是学的落后版本的,环境配置的又是新的,真蛋疼啊 :cry:
11F
$r = $db->pconnect( ‘p:’$cfg_db_hostname.$server, $cfg_db_username, $cfg_db_password, $cfg_db_name );
请问这个怎么改
10F
确实。 抱着老掉牙的东西咋进步
9F
大哥帮我看看
exec($sql) )return array();
if( ! mysql_num_rows($result) )return array();
$rows = array();
while($rows[] = mysql_fetch_array($result,MYSQL_ASSOC)){}
mysql_free_result($result);
array_pop($rows);
return $rows;
}
public function newinsertid()
{
return mysql_insert_id($this->conn);
}
public function showtables($tables)
{
return mysql_num_rows(mysql_query(“show tables like ‘%”.$tables.”%'”,$this->conn));
}
public function setlimit($sql, $limit)
{
return $sql. ” LIMIT {$limit}”;
}
public function exec($sql)
{
$this->arrSql[] = $sql;
if( $result = mysql_query($sql, $this->conn) ){
return $result;
}else{
if(mysql_error()!=”){
syError(“{$sql}执行错误: ” . mysql_error());
}else{
return TRUE;
}
}
}
public function affected_rows()
{
return mysql_affected_rows($this->conn);
}
public function getTable($tbl_name)
{
return $this->getArray(“DESCRIBE {$tbl_name}”);
}
public function __construct($dbConfig)
{
$linkfunction = ( TRUE == $dbConfig[‘persistent’] ) ? ‘mysql_pconnect’ : ‘mysql_connect’;
$this->conn = $linkfunction($dbConfig[‘host’].”:”.$dbConfig[‘port’], $dbConfig[‘login’], $dbConfig[‘password’]);
if(!$this->conn || !mysql_select_db($dbConfig[‘database’], $this->conn)){
echo ‘数据库无法链接,如果您是第一次使用,请先执行安装程序网润科技建站程序 m.cqbaidu.com‘;exit;
}
$this->exec(“SET NAMES UTF8”);
if($this->version() > ‘5.0.1’) {
$this->exec(“set sql_mode=””);
}
}
public function version() {
return mysql_get_server_info($this->conn);
}
public function __val_escape($value) {
return ‘\”.$value.’\”;
}
public function __destruct()
{
if( TRUE != $GLOBALS[‘G_DY’][‘db’][‘persistent’] )@mysql_close($this->conn);
}
}
8F
能帮我改改吗?
exec($sql) )return array();
if( ! mysql_num_rows($result) )return array();
$rows = array();
while($rows[] = mysql_fetch_array($result,MYSQL_ASSOC)){}
mysql_free_result($result);
array_pop($rows);
return $rows;
}
public function newinsertid()
{
return mysql_insert_id($this->conn);
}
public function showtables($tables)
{
return mysql_num_rows(mysql_query(“show tables like ‘%”.$tables.”%'”,$this->conn));
}
public function setlimit($sql, $limit)
{
return $sql. ” LIMIT {$limit}”;
}
public function exec($sql)
{
$this->arrSql[] = $sql;
if( $result = mysql_query($sql, $this->conn) ){
return $result;
}else{
if(mysql_error()!=”){
syError(“{$sql}执行错误: ” . mysql_error());
}else{
return TRUE;
}
}
}
public function affected_rows()
{
return mysql_affected_rows($this->conn);
}
public function getTable($tbl_name)
{
return $this->getArray(“DESCRIBE {$tbl_name}”);
}
public function __construct($dbConfig)
{
$linkfunction = ( TRUE == $dbConfig[‘persistent’] ) ? ‘mysql_pconnect’ : ‘mysql_connect’;
$this->conn = $linkfunction($dbConfig[‘host’].”:”.$dbConfig[‘port’], $dbConfig[‘login’], $dbConfig[‘password’]);
if(!$this->conn || !mysql_select_db($dbConfig[‘database’], $this->conn)){
echo ‘数据库无法链接,如果您是第一次使用,请先执行安装程序网润科技建站程序 m.cqbaidu.com‘;exit;
}
$this->exec(“SET NAMES UTF8”);
if($this->version() > ‘5.0.1’) {
$this->exec(“set sql_mode=””);
}
}
public function version() {
return mysql_get_server_info($this->conn);
}
public function __val_escape($value) {
return ‘\”.$value.’\”;
}
public function __destruct()
{
if( TRUE != $GLOBALS[‘G_DY’][‘db’][‘persistent’] )@mysql_close($this->conn);
}
}
7F
能帮我改改吗?
exec($sql) )return array();
if( ! mysql_num_rows($result) )return array();
$rows = array();
while($rows[] = mysql_fetch_array($result,MYSQL_ASSOC)){}
mysql_free_result($result);
array_pop($rows);
return $rows;
}
public function newinsertid()
{
return mysql_insert_id($this->conn);
}
public function showtables($tables)
{
return mysql_num_rows(mysql_query(“show tables like ‘%”.$tables.”%'”,$this->conn));
}
public function setlimit($sql, $limit)
{
return $sql. ” LIMIT {$limit}”;
}
public function exec($sql)
{
$this->arrSql[] = $sql;
if( $result = mysql_query($sql, $this->conn) ){
return $result;
}else{
if(mysql_error()!=”){
syError(“{$sql}执行错误: ” . mysql_error());
}else{
return TRUE;
}
}
}
public function affected_rows()
{
return mysql_affected_rows($this->conn);
}
public function getTable($tbl_name)
{
return $this->getArray(“DESCRIBE {$tbl_name}”);
}
public function __construct($dbConfig)
{
$linkfunction = ( TRUE == $dbConfig[‘persistent’] ) ? ‘mysql_pconnect’ : ‘mysql_connect’;
$this->conn = $linkfunction($dbConfig[‘host’].”:”.$dbConfig[‘port’], $dbConfig[‘login’], $dbConfig[‘password’]);
if(!$this->conn || !mysql_select_db($dbConfig[‘database’], $this->conn)){
echo ‘数据库无法链接,如果您是第一次使用,请先执行安装程序网润科技建站程序 m.cqbaidu.com‘;exit;
}
$this->exec(“SET NAMES UTF8”);
if($this->version() > ‘5.0.1’) {
$this->exec(“set sql_mode=””);
}
}
public function version() {
return mysql_get_server_info($this->conn);
}
public function __val_escape($value) {
return ‘\”.$value.’\”;
}
public function __destruct()
{
if( TRUE != $GLOBALS[‘G_DY’][‘db’][‘persistent’] )@mysql_close($this->conn);
}
}
6F
作者您好,如果是mysql_pconnect的话该怎么改呢
B1
@ 消失的853 在主机前面加上 p:
如 $mysqli = new mysqli(‘p:‘"localhost", "user", "password", "database");
B2
@ 默北 大哥能帮我看下吗 我的好像跟你写的不一样不知道怎么改
B2
@ 默北 大哥帮我看看
exec($sql) )return array();
if( ! mysql_num_rows($result) )return array();
$rows = array();
while($rows[] = mysql_fetch_array($result,MYSQL_ASSOC)){}
mysql_free_result($result);
array_pop($rows);
return $rows;
}
public function newinsertid()
{
return mysql_insert_id($this->conn);
}
public function showtables($tables)
{
return mysql_num_rows(mysql_query(“show tables like ‘%”.$tables.”%'”,$this->conn));
}
public function setlimit($sql, $limit)
{
return $sql. ” LIMIT {$limit}”;
}
public function exec($sql)
{
$this->arrSql[] = $sql;
if( $result = mysql_query($sql, $this->conn) ){
return $result;
}else{
if(mysql_error()!=”){
syError(“{$sql}执行错误: ” . mysql_error());
}else{
return TRUE;
}
}
}
public function affected_rows()
{
return mysql_affected_rows($this->conn);
}
public function getTable($tbl_name)
{
return $this->getArray(“DESCRIBE {$tbl_name}”);
}
public function __construct($dbConfig)
{
$linkfunction = ( TRUE == $dbConfig[‘persistent’] ) ? ‘mysql_pconnect’ : ‘mysql_connect’;
$this->conn = $linkfunction($dbConfig[‘host’].”:”.$dbConfig[‘port’], $dbConfig[‘login’], $dbConfig[‘password’]);
if(!$this->conn || !mysql_select_db($dbConfig[‘database’], $this->conn)){
echo ‘数据库无法链接,如果您是第一次使用,请先执行安装程序网润科技建站程序 m.cqbaidu.com‘;exit;
}
$this->exec(“SET NAMES UTF8”);
if($this->version() > ‘5.0.1’) {
$this->exec(“set sql_mode=””);
}
}
public function version() {
return mysql_get_server_info($this->conn);
}
public function __val_escape($value) {
return ‘\”.$value.’\”;
}
public function __destruct()
{
if( TRUE != $GLOBALS[‘G_DY’][‘db’][‘persistent’] )@mysql_close($this->conn);
}
}
5F
取消mysql的用户 怎么理解呢?
4F
搞了一下午才看到你的高见。求教: public function __construct($hostname, $username, $password, $database) {
if (!$this->link = mysql_connect($hostname, $username, $password)) {
trigger_error(‘Error: Could not make a database link using ‘ . $username . ‘@’ . $hostname);
}
怎么改呢?
B1
@ 再见帅人智 $mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
3F
感谢
2F
用PDO更好,性能好又安全。PDO是趋势
1F
确实。 抱着老掉牙的东西咋进步
来自外部的引用