warning: mysqli_error() expects parameter 1 to be mysqli, 0 given

Hello all,

I’m transitioning into mysqli, and seem to be missing a few details. I keep getting the following error message:
mysqli_error() expects parameter 1 to be mysqli, 0 given in …path/… on line 222

[php]
//$conn(ection) works fine in previous queries in same page
$conn=dbConnect(‘query’);

if($top_gun_id) {
//get specs from db using foreign key
$sqli = “SELECT * FROM great_movies WHERE top_secret_info.top_gun = $top_gun_id”; /*where top_secret_info is another table */

            //the following is the line (222) in question
	$get_gun = $conn->query($sqli) or die(mysqli_error());
	$alt_row = $get_gun->fetch_assoc();
	while($alt_row) {
		echo "$alt_row\r\r";
	}
	//do x,y, and even z

}
[/php]

After much reading, I can’t find anything conclusive, but have the impression that if you’re only reading from a db and not inserting, mysqli does not require a prepared statement ? Is that my whole problem? Should $sqli read:
[php]$sqli = 'SELECT * FROM great_movies WHERE ? = ?[/php]
and so on? I feel like I’ve tried that too, but can’t remember anymore.

One last thing, I typed: [php]or die(mysqli_error($get_gun)[/php]
and received: mysqli_error() expects parameter 1 to be mysqli, boolean given in …path/… on line 222
Thanks in advance.

UPDATE: No longer getting error message. It turns out that I did/do need to prepare the statement. But, now I need to figure out how to use results equivalent to while($row…) statement
[php]//…include() file reference, for newbiers than me
function dbConnect($type) {
if($type == ‘query’) {
//local
$user=‘root’;
$pwd=‘root’;
}
}//end include reference
//$conn established early
$conn=dbConnect(‘query’);

if ($top_gun_id) {
//get specs from db
//prepare stmt
$sqli = ‘SELECT * FROM great_movies WHERE top_secret_info.top_gun = ?’;
$stmt = $conn->stmt_init();
if($stmt->prepare($sqli)) {
//bind
$stmt->bind_param(‘i’,"$top_gun_id");
//execute
$stmt->execute();
/* NOW WHTAT! */
}//end if[/php]
so, now I need to know what the mysqli equivalent is to
[php]while ($row = mysql_fetch_assoc($result))[/php]
Thanks.

Sponsor our Newsletter | Privacy Policy | Terms of Service