网站迁移后,我得到一个MySQL错误不推荐:mysql_pconnect():
问题描述:
对不起,我对PHP没有太多的了解,我需要一点帮助将一个网站从一台服务器迁移到另一台服务器,服务器有操作系统和PHP 旧版本的移动过的文件到新的服务器和数据库我运行的网站,并获得网站迁移后,我得到一个MySQL错误不推荐:mysql_pconnect():
弃用后:mysql_pconnect():mysql扩展已被弃用, 将被删除在未来:使用mysqli或PDO代替 /var/www/classes/dbcon.class.php 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();
}
的可能的复制[推荐使用:MySQL的\ _pconnect():](https://stackoverflow.com/q/22834458/6521116) –
的MySQL _ *()是deprecated.so使用mysqli的_ *() –
如我说我对PHP没有太多的了解,并且尝试用mysqli替换mysql_pconnect行,但它似乎并不简单 – MikeAsp