PHP Mysql to Mysqli mistakes >> mysqli_query expects parameter 1 to be mysqli
Rishi Kashyap
8.72 K
X

mysqli_query expects parameter 1 to be mysqli


0

Error "mysqli_query() expects parameter 1 to be mysqli" was thrown and made me waste 2 days finding this silly mistake.
When we use mysql_query() we simply place the query string first followed by the link identifier(connection)<?php
$link = mysql_connect('localhost','user','password') or die(mysql_error());
$q= mysql_query("Query string",$link) or die(mysql_error());
var_dump(mysql_fetch_array ($q));
?>
But when using mysqli_query(), the link comes first followed by the query string. Simple PHP Mysqli code in procedural style<?php
$link = mysqli_connect('localhost','user','password') or die(mysqli_error($link));
$q= mysqli_query($link,"Query string") or die(mysqli_error($link));
var_dump(mysqli_fetch_array ($q));
?>
Please note that I use the Database.Table format in my query strings and hence the Database details are omitted in Mysql/Mysqli connect.

Rishi Kashyap | | EDIT

SHARE Whatsapp Facebook Twitter To TOP