Does mysql_query ($ SQL) return the boolen value or resourceid? How can this problem be solved?

Source: Internet
Author: User
Does mysql_query ($ SQL) return the boolen value or resourceid ??? PHPcode & lt ;? Php $ SQL & quot; SELECT * FROMUserInfoWHEREid222 & quot; $ sql2 & quot; SELECTTOP1 * FROMUserInfoWHEREid222 & quot; m mysql_query ($ SQL) whether the returned boolen value is the resource id ???
PHP code
  
  

If SQL is used, the output is OK. the user existResource id #4
If sql2 is used, the output is the user not exist.

Declare that the data with id = 222 does not exist in the database. why is there such a result?
For SQL queries, resource IDs are returned, and SQL 2 is used for queries. a Boolean value is returned. why?



------ Solution --------------------
If the query is successful, the resource id is returned, which has nothing to do with the result.
Use mysql_num_rows to obtain the number of rows in the query result.
------ Solution --------------------
$ Result = mysql_query ($ SQL );

If (! $ Mysql_num_rows ($ result )){
Echo ("the user not exist ");
} Else {
Echo ("OK, login sucsuss );
}
------ Solution --------------------
PHP code
Mysql_query-send a MySQL query description resource mysql_query (string $ query [, resource $ link_identifier]) mysql_query () sends a query to the active database in the server associated with the specified connection identifier. If link_identifier is not specified, the last opened connection is used. If no connection is enabled, this function will try to call the mysql_connect () function without parameters to establish a connection and use it. The query results are cached. Note: the query string should not end with a semicolon. Mysql_query () only returns a resource identifier for SELECT, SHOW, EXPLAIN or DESCRIBE statements. if the query execution is incorrect, FALSE is returned. For other types of SQL statements, if mysql_query () is executed successfully, TRUE is returned. If an error occurs, FALSE is returned. If the return value is not FALSE, the query is legal and can be executed by the server. This does not indicate any affected or returned number of rows. It is very likely that a query is successfully executed but does not affect or no rows are returned. The following query syntax is incorrect, so mysql_query () fails and FALSE is returned: Example #1 mysql_query () Example
  
   
The following query has a semantic error when my_col is not a column in my_tbl. Therefore, mysql_query () fails and FALSE is returned: Example #2 mysql_query ()
   If you do not have the permission to access the table referenced in the query statement, mysql_query () returns FALSE. If the query is successful, you can call mysql_num_rows () to check the number of rows returned by the SELECT statement, or call mysql_affected_rows () to check the values corresponding to DELETE, INSERT, the number of rows affected by the REPLACE or UPDATE statement. A new result identifier is returned only for SELECT, SHOW, DESCRIBE, or EXPLAIN statement mysql_query (). It can be passed to the functions of mysql_fetch_array () and other processing result tables. After processing the final result set, you can call mysql_free_result () to release the associated resources, even though the memory is automatically released after the script is executed. See mysql_num_rows (), rows (), rows (), mysql_free_result (), mysql_fetch_array (), mysql_fetch_row (), rows (), mysql_result (), mysql_select_db () and mysql_connect ().
   

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.