因为是自学PHP+SQL新手
目前尚在摸索阶段
在网络上找了一些资料来研究
XAMPP灌好要跑
都出现错误讯息
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\html\include\db_class.php:15
研究了好几天,无法搞定
也知道PHP7.3已经都不支援mysql_connect()函数
所以尝试改这个档案,看了好多资料
都改失败....一直出现错误讯息
可以请教各位前辈,像这种物件
物件导向的方式,DB_Class.php中的里面的mysql旧函数要改mysqli要如何改呢?
是否有高手可以教一下~~~
DB_config.php
<?php
global $_DB;
$_DB['host'] = "localhost";
$_DB['username'] = "username";
$_DB['password'] = "password";
$_DB['dbname'] = "db_name";
?>
DB_Class.php档的
<?php
class DB
{
var $_dbConn = 0;
var $_queryResource = 0;
function DB()
{
//do nothing
}
function connect_db($host, $user, $pwd, $dbname)
{
$dbConn = mysql_connect($host, $user, $pwd);
if (! $dbConn)
die ("MySQL Connect Error");
mysql_query("SET NAMES utf8");
if (! mysql_select_db($dbname, $dbConn))
die ("MySQL Select DB Error");
$this->_dbConn = $dbConn;
return true;
}
function query($sql)
{
if (! $queryResource = mysql_query($sql, $this->_dbConn))
die ("MySQL Query Error");
$this->_queryResource = $queryResource;
return $queryResource;
}
/** Get array return by MySQL */
function fetch_array()
{
return mysql_fetch_array($this->_queryResource, MYSQL_ASSOC);
}
function get_num_rows()
{
return mysql_num_rows($this->_queryResource);
}
/** Get the cuurent id */
function get_insert_id()
{
return mysql_insert_id($this->_dbConn);
}
}
?>