how to convert MySQL to MySQLi

Ask about a PHP problem here.
Post Reply
9pleum
Posts: 3
Joined: Thu Sep 26, 2013 11:18 am

how to convert MySQL to MySQLi

Post by 9pleum »

Convert this
return (mysql_result($total, 0) == '1') ? true : false;
to MySQLI ?




.....................
sorry for my eng :D
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: how to convert MySQL to MySQLi

Post by ScTech »

Need to see the query for it. Based on the ternary operator, you could probably use mysqli_num_rows();
<?php while(!$succeed = try()); ?>
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: how to convert MySQL to MySQLi

Post 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.
9pleum
Posts: 3
Joined: Thu Sep 26, 2013 11:18 am

Re: how to convert MySQL to MySQLi

Post by 9pleum »

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; 
}
i don't understand this line ;'c
return (mysql_result($total, 0) == '1') ? true : false; 
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: how to convert MySQL to MySQLi

Post by Temor »

you need to fetch that line through mysqli
$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;
9pleum
Posts: 3
Joined: Thu Sep 26, 2013 11:18 am

Re: how to convert MySQL to MySQLi

Post by 9pleum »

Ohh, thank you :D
Voiceeeeee
Posts: 1
Joined: Sun Nov 03, 2013 1:00 pm

Re: how to convert MySQL to MySQLi

Post 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.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: how to convert MySQL to MySQLi

Post by Temor »

That is actually pretty useful. Neat table.
Wish I had that back when..
User avatar
killfrog47
Posts: 106
Joined: Tue Mar 12, 2013 2:52 am
Location: Tempe, AZ
Contact:

Re: how to convert MySQL to MySQLi

Post 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
Post Reply