Someone please help me with sql

krahny

New Member
Messages
25
Reaction score
0
Points
0
I was wondering if anyone knows what the sql select command will return in a query if it finds no match. Or, maybe there's a way to check if a record exists with a certain value.

Somone please help.
 

krahny

New Member
Messages
25
Reaction score
0
Points
0
I know that code, but I need to know what it returns if it finds no match to the value.

Thanks anyway.
 

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
Handling in PHP

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.


Only SQL

Empty set (0.00 sec)
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
PHP:

PHP:
# $dbh is the connection to your database
 
$sql = "SELECT name, city  FROM customer_table WHERE state='CA' " ;
 
$result = mysqli_query(  $dbh , $sql ) ;
 
if( $result === false ){
   # HANDLE ERROR ;
} elseif ( mysqli_num_rows( $result ) == 0 ) {
   # HANDLE  NO MATCH 
} else {
   # HANDLE AT LEAST ONE MATCH
}
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I know that code, but I need to know what it returns if it finds no match to the value.
Notionally, the empty set. Relational DBMSs, such as MySQL, are modeled after relationships, which are relations ([2]) where you don't care about domain order. In RDB parlance, "table" is synonymous with "relationship". An SQL statement creates a new relationship by joining, filtering and sorting other relationships. If a join or a filter results in no tuples (rows), the result is an empty set.

In PHP, the various MySQL drivers invariably return a result with no rows. If you want to test for an empty result, use (e.g.) mysqli_num_rows or PDOStatement::rowCount.
 

krahny

New Member
Messages
25
Reaction score
0
Points
0
Thanks!

Thanks for your help!

That code descalzo gave me worked Great!!

:biggrin:
 
Top