gpt4 book ai didi

php - 网站迁移后,我收到 MySQL 错误 Deprecated : mysql_pconnect():

转载 作者:行者123 更新时间:2023-11-29 18:55:17 25 4
gpt4 key购买 nike

抱歉,我对 PHP 不太了解,我需要一些帮助,将网站从一台服务器迁移到另一台服务器,而且旧服务器似乎有旧版本的操作系统和 PHP将文件移至新服务器和数据库后,我运行该站点并得到

Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/classes/dbcon.class.php on line 45

这是该文件中的代码,我尝试更改几行并尝试使用 MySqli,但我似乎无法让它工作。

<?php



class dbCon
{
//
// private variables
//

var $_hostname_Con;
var $_database_Con;
var $_username_Con;
var $_password_Con;
var $_Con;

var $_result;
var $_hasData;
var $_lastQuery;
var $_row;
var $_rowCount;

//
// methods (private)
//

//
// methods (public)
//

// constructor
function dbCon()

{
$this->_hostname_Con = "localhost";
$this->_database_Con = "street";
$this->_username_Con = "rt";
$this->_password_Con = "mwL";
//*
$this->_database_Con = "cranes_cms";
$this->_username_Con = "t";
$this->_password_Con = "mob";
//*/

$this->_Con = mysql_pconnect ($this->_hostname_Con, $this->_username_Con, $this->_password_Con) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($this->_database_Con) or die('Could not select database');
}

function freeResult()
{
mysql_free_result($this->_result);
}

function close()
{
mysql_close($this->_Con);
}


function update($inQuery)
{
//reset row counter and data flag
$this->_rowCount = 0;
$this->_hasData = FALSE;

//do SQL
$this->_lastQuery = $inQuery;
mysql_query($this->_lastQuery,$this->_Con) or die('Query failed: ' . mysql_error());
}

function select($inQuery)
{
//reset row counter and data flag
$this->_rowCount = 0;
$this->_hasData = FALSE;

//do SQL
$this->_lastQuery = $inQuery;
$this->_result = mysql_query($this->_lastQuery,$this->_Con) or die('Query failed: ' . mysql_error());

//set has data flag
if (mysql_num_rows($this->_result))
{$this->_rowCount = mysql_num_rows($this->_result);}
else
{$this->_rowCount = 0; }

if ( $this->_rowCount > 0)
{$this->_hasData = TRUE;}
else
{$this->_hasData = FALSE;}

}

function getData()
{
if ($this->_hasData)
{
if ($this->_row = mysql_fetch_array($this->_result, MYSQL_ASSOC))
{
return $this->_row;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
}

function getRowCount()
{
return $this->_rowCount;
}

function hasData()
{
return $this->_hasData;
}
// end
}

?>

这是别人的代码,我不知道在哪里解决这个问题。任何人都可以吗

最佳答案

这是一个使用 mysqli_*() 的示例,您可以了解更多 here .

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}

/* Create table doesn't return a resultset */
if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
printf("Table myCity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) {
printf("Select returned %d rows.\n", $result->num_rows);

/* free result set */
$result->close();
}

关于php - 网站迁移后,我收到 MySQL 错误 Deprecated : mysql_pconnect():,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44172496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com