Speechless error, mysql_fetch_array ()

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.