Maison >développement back-end >tutoriel php > 无语的失误,mysql_fetch_array()
无语的出错,mysql_fetch_array()
代码如下,求帮忙看一下吧!
<?php<br /> class Conn{<br /> private $dbhost = ""; //服务器<br /> private $dbuser = ""; //mysql帐号<br /> private $dbpsw = ""; //mysql密码<br /> private $dbchar = ""; //数据库编码类型<br /> private $dbname = ""; //数据库名称<br /> private $tablepre = ""; //表前缀<br /> private $conn = NULL; //连接对象 <br /> <br /> /**<br /> * 数据库链接初始化<br /> */<br /> public function __construct(){<br /> $this->getConn();<br /> }<br /> <br /> public function getConn(){<br /> $db = require_once 'config/config.php';<br /> $this->dbhost = $db['dbhost'];<br /> $this->dbuser = $db['dbuser'];<br /> $this->dbpsw = $db['dbpsw'];<br /> $this->dbchar = $db['dbchar'];<br /> $this->dbname = $db['dbname'];<br /> $this->tablepre = $db['tablepre'];<br /> $this->conn = mysql_connect($this->dbhost,$this->dbuser,$this->dbpsw) or die(mysql_error()."<br/>Mysql连接失败!");<br /> mysql_select_db($this->dbname,$this->conn) or die(mysql_error()."<br/>数据库访问出错");<br /> mysql_query("set names ".$this->dbchar,$this->conn);<br /> }<br /> <br /> /**<br /> * 执行sql<br /> */<br /> public function query($sql){<br /> return mysql_query($sql,$this->conn) or die(mysql_error()."<br/>SQL执行出错:$sql");<br /> }<br /> <br /> /**<br /> * 返回多条记录<br /> */<br /> public function getDataArrays($sql,$type = MYSQL_BOTH){<br /> $result = $this->query($sql);<br /> $refArr = array();<br /> <span style="color: #FF0000;">while ($row = mysql_fetch_array($result,$type)){</span><br /> $refArr[] = $row;<br /> }<br /> return $refArr;<br /> }<br /> <br /> <br /> /**<br /> * 关闭数据库链接<br /> */<br /> public function closeConn(){<br /> mysql_close($this->conn);<br /> }<br /> }
$conn = new Conn();<br /> $sql = "select * from qj_content";<br /> $contentList = $conn->getDataArrays($sql,MYSQL_ASSOC);<br /> $conn->closeConn();