Speechless error. the mysql_fetch_array () code is as follows. please take a look! & Lt ;? Phpclass & nbsp; Conn {private & nbsp; $ dbhost & nbsp; = & nbsp; ""; // server private & nbsp; $ dbuse error in speechless, mysql_fetch_array ()
The code is as follows. please take a look!
Class Conn {
Private $ dbhost = ""; // server
Private $ dbuser = ""; // mysql account
Private $ dbpsw = ""; // mysql password
Private $ dbchar = ""; // database encoding type
Private $ dbname = ""; // database name
Private $ tablepre = ""; // table prefix
Private $ conn = NULL; // connection object
/**
* Database link initialization
*/
Public function _ construct (){
$ This-> getConn ();
}
Public function getConn (){
$ Db = require_once 'config/config. php ';
$ This-> dbhost = $ db ['dbhost'];
$ This-> dbuser = $ db ['dbuser'];
$ This-> dbpsw = $ db ['dbpsw'];
$ This-> dbchar = $ db ['dbchar '];
$ This-> dbname = $ db ['dbname'];
$ This-> tablepre = $ db ['tablepre'];
$ This-> conn = mysql_connect ($ this-> dbhost, $ this-> dbuser, $ this-> dbpsw) or die (mysql_error ()."
Mysql connection failed! ");
Mysql_select_db ($ this-> dbname, $ this-> conn) or die (mysql_error ()."
Database access error ");
Mysql_query ("set names". $ this-> dbchar, $ this-> conn );
}
/**
* Execute SQL
*/
Public function query ($ SQL ){
Return mysql_query ($ SQL, $ this-> conn) or die (mysql_error ()."
SQL execution error: $ SQL ");
}
/**
* Multiple records are returned.
*/
Public function getDataArrays ($ SQL, $ type = MYSQL_BOTH ){
$ Result = $ this-> query ($ SQL );
$ RefArr = array ();
While ($ row = mysql_fetch_array ($ result, $ type )){
$ RefArr [] = $ row;
}
Return $ refArr;
}
/**
* Close the database link
*/
Public function closeConn (){
Mysql_close ($ this-> conn );
}
}
The call is as follows:
$conn = new Conn();
$sql = "select * from qj_content";
$contentList = $conn->getDataArrays($sql,MYSQL_ASSOC);
$conn->closeConn();
The execution result is as follows:
Warning: mysql_fetch_array (): supplied argument is not a valid MySQL result resource in D: \ AppServ \ www \ qjcentury \ conn. php on line 45
The 45th lines of code marked the MySQL PHP database connection query in red.