mysql check if query ran already code example
Example 1: node js check if a user exists in mysql
connectDB.query("SELECT ACCOUNT_ID FROM registration WHERE ACCOUNT_ID = '"+ userAccnt +"'", function(err, result, field){
if(result.length === 0){
//new user logic
}else{
//existing user, redirect to another page
}
}
Example 2: php check if query succeeded
<?php
// peform a query
$query = "SELECT `*` FROM user";
$results = mysqli_query($databaseConnection, $query);
if (mysqli_num_rows($results) == 0) {
// The query returned 0 rows!
} else {
// the query returned ATLEAST one row
}
if (mysqli_num_rows($results) >= 5) {
// the query returned more than 5 rows
}
?>