Warning: mysql_fetch_array () expectsparameter1toberesource, booleangiveni solution

Source: Internet
Author: User
Warning: mysql_fetch_array () handle, booleangiveni $ SQL = & quot; selectcount (uid) asuserfromu Warning: mysql_fetch_array () expects parameter 1 to be resource, boolean given I
$ SQL = "select count (uid) as user from user_table where uid = '". $ this-> username. "'and password = '". md5 ($ this-> password, self: USERCONST ). "'";
$ Query = $ this-> database-> setSQL ($ SQL );
If ($ row = $ this-> database-> select_array ($ query )){
Echo $ row ["user"];
Why can't I read only one record in the query results? if user = 1, it indicates that the user 1 or above is repeated.
The output result is:
Warning: mysql_fetch_array () expects parameter 1 to be resource, boolean given in F: \ wamp \ www \ user \ DB \ MySql. php on line 27
Ask for help


PHP code
  
  Database = new MySql (); $ this-> username = $ u; $ this-> password = $ p;} function register () {$ pmd5 = md5 ($ this-> password. self: USERCONST); $ SQL = "insert into user_table (username, password) values ('". $ this-> username. "','". $ pm5. "')"; $ database-> setSQL ($ SQL);} function logout () {echo "logout";} function login () {echo "login ";} function usercheck () {// password plus constant $ SQL = "select count (uid) as user from user_table Where uid = '". $ this-> username. "'and password = '". md5 ($ this-> password, self: USERCONST ). "'"; $ query = $ this-> database-> setSQL ($ SQL); if ($ row = $ this-> database-> select_array ($ query )) {echo $ row ["user"] ;}}}?>


PHP code
  
  Host = "localhost"; $ this-> username = "root"; $ this-> password = ""; $ this-> database = "bkqs "; $ this-> mysqlconnection ();} function mysqlconnection () {$ connection = mysql_connect ($ this-> host, $ this-> username, $ this-> password) or die ("failed to connect to the database"); mysql_select_db ($ this-> database, $ connection) or die ("failed to open the database "); mysql_query ("set names 'gbk'");} function setSQL ($ SQL) {return mysql_query ($ SQL);} function Select_array ($ query) {return mysql_fetch_array ($ query);} function select_object ($ query) {return mysql_fetch_object ($ query);} function close () {return mysql_close () ;}}?>



------ Solution --------------------
An error occurred while executing the SQL statement. You can add error messages in your setSQL () method. Or die (mysql_error (); you will know where the error is.

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.