Page 1 of 1

how to convert MySQL to MySQLi

Posted: Thu Sep 26, 2013 11:23 am
by 9pleum
Convert this
[syntax=php]return (mysql_result($total, 0) == '1') ? true : false;[/syntax]
to MySQLI ?




.....................
sorry for my eng :D

Re: how to convert MySQL to MySQLi

Posted: Thu Sep 26, 2013 1:58 pm
by ScTech
Need to see the query for it. Based on the ternary operator, you could probably use mysqli_num_rows();

Re: how to convert MySQL to MySQLi

Posted: Thu Sep 26, 2013 7:07 pm
by Temor
Well, if you wanna use MySQLi you'd have to change it throughout your code, not just on one line.

Here's an introduction to MySQLi.

Re: how to convert MySQL to MySQLi

Posted: Fri Sep 27, 2013 7:38 am
by 9pleum
[syntax=php]
function valid_credentials($user, $pass){
global $mysqli;
$user = $mysqli->real_escape_string($user);
$pass = $mysqli->real_escape_string($pass);

$total = $mysqli->query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'");

return (mysql_result($total, 0) == '1') ? true : false;
}
[/syntax]

i don't understand this line ;'c
[syntax=php]return (mysql_result($total, 0) == '1') ? true : false; [/syntax]

Re: how to convert MySQL to MySQLi

Posted: Fri Sep 27, 2013 8:09 am
by Temor
you need to fetch that line through mysqli

[syntax=php]$total = $mysqli->query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'");
$row = $total->fetch_row();
return ($row[0] == 1) ? true : false;[/syntax]

Re: how to convert MySQL to MySQLi

Posted: Fri Sep 27, 2013 8:48 am
by 9pleum
Ohh, thank you :D

Re: how to convert MySQL to MySQLi

Posted: Sun Nov 03, 2013 1:11 pm
by Voiceeeeee
Here's something that helped me when I decided to use MySQLi over MySQL, I hope it'll help you and other users.
Image
$cxn is the connection variable.
Image
If you want a function that's not in the image then just search for it in the PHP Docs and you'll see a warning saying MySQL is deprecated linking to the exact MySQLi and PDO function.

Re: how to convert MySQL to MySQLi

Posted: Sun Nov 03, 2013 1:33 pm
by Temor
That is actually pretty useful. Neat table.
Wish I had that back when..

Re: how to convert MySQL to MySQLi

Posted: Wed Nov 06, 2013 2:10 am
by killfrog47
Voiceeeeee wrote:Here's something that helped me when I decided to use MySQLi over MySQL, I hope it'll help you and other users.
Image
$cxn is the connection variable.
Image
If you want a function that's not in the image then just search for it in the PHP Docs and you'll see a warning saying MySQL is deprecated linking to the exact MySQLi and PDO function.

Nice! Im gonna have to save that table because I can NEVER remember these things lol im always googling the old MySQL way to see the MySQLi equivalent