Updating mysql to mysqli - Queries No Longer Work

Codes here !

Moderators: egami, macek, gesf

Post Reply
blisken
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Dec 25, 2017 7:27 pm

Mon Dec 25, 2017 7:38 pm

Hello All,

I am trying to update from mysql_query to mysqli_query and am having great difficulty.

Does the query structure change? I can not locate the solution for any type of mysqli query.

Here is my code that now fails. I am using PHP 5.6

Code: Select all

$ARRY = array("boatmotor","boatesc","prop","lipo");
$i = 1 ;
	foreach ($ARRY as $value)
	{ 
		${Lists.$i} = "";
		$result = mysqli_query($con,'SELECT DISTINCT manu FROM '.$value.'');
		while($row = mysqli_fetch_array($result))
		{
			${Lists.$i} = ${Lists.$i}.'<option value="'.$row["manu"].'" '.$selected.'>'.$row["manu"].'</option>'; 
			${Manufacture.$i} =  $row["manu"] ;
		}
		$i++ ;
	}
errors are as follows:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/content/66/7778566/html/wp-content/themes/graphene/page-1395.php on line 19

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/content/66/7778566/html/wp-content/themes/graphene/page-1395.php on line 19

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/content/66/7778566/html/wp-content/themes/graphene/page-1395.php on line 19

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/content/66/7778566/html/wp-content/themes/graphene/page-1395.php on line 19

This suggests that the function returns false meaning no query is actually completed?

I appreciate any help that can shed some light on what I am missing.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 686
Joined: Mon Feb 22, 2016 5:52 pm

Wed Dec 27, 2017 9:22 am

Does the query structure change?
No. The function calls have changed though. It's not just a case of adding an 'i' to the end of the function call name; some are completely different.

The point of changing to MySQLi was to write more secure code, you are not taking advantage of this and simply using the same insecure way of accessing a database. Have a look at the PDO interface instead of MySQLi and see if that makes more sense to you.

Post Reply