A
A
Artur Yalaltdinov2016-05-06 21:25:15
MySQL
Artur Yalaltdinov, 2016-05-06 21:25:15

How to make validation and SQL query?

Hi everyone, I have this code

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '',
  database : 'database'
});
connection.connect();
var queryString = 'SELECT * FROM table WHERE id = 4 AND paid = 9 LIMIT 0, 1';
 
connection.query(queryString, function(err, rows, fields) {
  if (err) {
    console.log("ERROR");
  }
  else 
  {
    if(rows.length != 0)
    {
      console.log("FOUND");
    }
    else 
    {
      console.log("NOT FOUND");
    }
  }
});
connection.end();

And the question is
How to do it as shown below? otherwise it always returns "FOUND" to me, regardless of whether there is anything in the table or not.
$mysqli = new mysqli("localhost", "root", "", "database");

$query = $mysqli->query("SELECT * FROM `table` WHERE `id` = '5'");
if($query->fetch_array())
{
  echo "FOUND";
}
else
{
  echo "NOT FOUND";
}
$mysqli->close();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question