mysql_query ($sql) whether the Boolen value or the resource ID is returned???
PHP Code
If SQL is used, the output is OK, the user existresource ID #4
If using SQL2, the output is the user not exist
Declare that the data of id = 222 does not exist in the database, why is there such a result?
With SQL query, return the resource ID, with SQL2 query, return is a Boolean value, why?
------Solution--------------------
The resource ID is returned when the query succeeds, and it doesn't matter how much the result is.
Gets the number of rows for the query result with mysql_num_rows
------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-sends a MySQL Query description resource mysql_query (string $query [, Resource $link _identifier]) mysql_query () to the specified connection identifier Sends a query to the currently active database in the associated server. If Link_identifier is not specified, the previous open connection is used. If there is no open connection, this function attempts to call the mysql_connect () function without arguments to establish a connection and use it. The query results are cached. Note: The query string should not end with a semicolon. mysql_query () returns a resource identifier only for Select,show,explain or DESCRIBE statements, or FALSE if the query is executed incorrectly. For other types of SQL statements, mysql_query () returns TRUE on successful execution and returns FALSE on error. A return value other than FALSE means that the query is legitimate and can be executed by the server. This does not indicate any information about the number of rows affected or returned. It is possible that a query executed successfully but did not affect or return any rows. The following query has syntax errors, so mysql_query () fails and returns False:example #1 mysql_query () example
If you do not have permission to access the table referenced in the query statement, mysql_query () also returns FALSE. Assuming the query succeeds, you can call Mysql_num_rows () to see how many rows are returned for the SELECT statement, or call Mysql_affected_rows () to view the corresponding delete,insert,replace or UPDATE How many rows are affected by the statement. Only the Select,show,describe or EXPLAIN statement mysql_query () returns a new result identifier that can be passed to mysql_fetch_array () and other functions that process the result table. After the result set has been processed, the associated resource can be freed by calling Mysql_free_result (), although the memory is freed automatically when the script finishes executing. See Mysql_num_rows (), Mysql_affected_rows (), Mysql_unbuffered_query (), Mysql_free_result (), mysql_fetch_array (),
Mysql_fetch_row (), Mysql_fetch_assoc (), mysql_result (), mysql_select_db () and mysql_connect ().