Convert this
[syntax=php]return (mysql_result($total, 0) == '1') ? true : false;[/syntax]
to MySQLI ?
.....................
sorry for my eng
how to convert MySQL to MySQLi
Re: how to convert MySQL to MySQLi
Need to see the query for it. Based on the ternary operator, you could probably use mysqli_num_rows();
<?php while(!$succeed = try()); ?>
Re: how to convert MySQL to MySQLi
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.
Here's an introduction to MySQLi.
Re: how to convert MySQL to MySQLi
[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]
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
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]
[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
Ohh, thank you
-
- Posts: 1
- Joined: Sun Nov 03, 2013 1:00 pm
Re: how to convert MySQL to MySQLi
Here's something that helped me when I decided to use MySQLi over MySQL, I hope it'll help you and other users.
$cxn is the connection variable.
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.
$cxn is the connection variable.
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
That is actually pretty useful. Neat table.
Wish I had that back when..
Wish I had that back when..
- killfrog47
- Posts: 106
- Joined: Tue Mar 12, 2013 2:52 am
- Location: Tempe, AZ
- Contact:
Re: how to convert MySQL to MySQLi
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.
$cxn is the connection variable.
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