Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in

Tags:

php

mysqli

I got the warning:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in (...) on line 6

My code is here:

<?php

require_once 'conn.php';

$sql = "SELECT user_id, access_lvl, name FROM cms_users ";
$result = mysqli_query($sql, $conn);
like image 270
lixle Avatar asked Dec 04 '22 05:12

lixle


2 Answers

It's exactly as the error states as you're passing arguments to mysqli_query() incorrectly. Assuming $conn is your mysqli connection generated at some point by new mysqli() it should be:

$result = mysqli_query( $conn,$sql) or trigger_error(mysqli_error($conn)));

The way you were calling it you were passing a string, $sql as the first argument.

like image 111
Ray Avatar answered Jan 17 '23 05:01

Ray


I was having this this problem but after swiping $result = mysqli_query($sql, $conn) to $result = mysqli_query( $conn,$sql)

I manage to solve this error

like image 45
Zakhele Harries Avatar answered Jan 17 '23 05:01

Zakhele Harries