首页 >后端开发 >php教程 > 无语的失误,mysql_fetch_array()

无语的失误,mysql_fetch_array()

WBOY
WBOY原创
2016-06-13 12:39:24711浏览

无语的出错,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();


执行结果如下:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\qjcentury\conn.php on line 45


第45行代码在上面用红色标注了

MySQL PHP 数据库连接 查询
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn