php mysql if exists code example
Example 1: php mysql if exists
$mysqli = new mysqli(SERVER, DBUSER, DBPASS, DATABASE);
$result = $mysqli->query("SELECT id FROM mytable WHERE city = 'c7'");
if($result->num_rows == 0) {
// row not found, do stuff...
} else {
// do other stuff...
}
$mysqli->close();
Example 2: mysql check if value exists
mysql> SELECT EXISTS(SELECT * from ExistsRowDemo WHERE ExistId=105);