Can you give me the equivalent of this code im MySQLi? Can’t get it right.
<?php
if(mysql_num_rows(mysql_query("SELECT userid FROM users WHERE userid = '$userid'"))){
//code to be exectued if user exists
}
?>
EDIT: Care to explain to me what is wrong?
$mysqli = new mysqli($host, $username, $pass, $db);
if ($mysqli->connect_error) {
die('The Server Is Busy. Please Try Again Later.');
}
$result = $mysqli->query("SELECT userid FROM users WHERE userid = '$userid'");
if ($result->num_rows) {
echo "<h1>AWESOME</h1>";
}
Well, in an OO sense, it would go from:
To (assuming numeric userid):
To (assuming string userid) :
To (assuming prepared statements) :
Now, that’s assuming you’re using the OOP version of MySQLi (which you should be, IMHO, since it makes life easier in a lot of ways).