不推荐使用:mysql_pconnect():不推荐使用mysql扩展名 将来将被删除:使用mysqli或PDO代替 第45行/var/www/classes/dbcon.class.php
这里是该文件中的代码我尝试更改几行并尝试使用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
}
?>
这是别人的代码,我不知道在哪里解决这个问题。有人可以吗
答案 0 :(得分:0)
这是一个使用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();
}