开发者

What am I doing wrong with handling that global with the mysqli_query? [duplicate]

This question already has answers here: mysqli_query() expects at least 2 parameters, 1 given (5 answers) Closed 3 years ago.

I have a global [global $host,$user,$passwd,$dbname;] for connecting to database in my script and then I use mysqli_query to perform a simple update query. There is a connection, but I keep getting this error:

mysqli_query() expects at least 2 parameters,

What am I doing wrong with handling that global开发者_JS百科 with the mysqli_query? Or is this error given when there is a problem with the query itself?


It means that mysqli expects this:

 $result = mysqli_query($dbh, "SELECT ...");

and you're probably doing this:

 $result = mysqli_query("SELECT ...");

The mysqli library is not a direct drop-in replacement for the older mysql one (note the lack of an i).


ok. simple short pseudo-code sample:

$dbh = mysqli_connect(....) or die(mysqli_connect_error());

function do_something($blah) {
   global $dbh;
   $result = mysqli_query($dbh, "SELECT ... $blah") or die(mysqli_error($dbh));
}


PHP Documentation: http://us2.php.net/mysqli_query

mysqli_query requires two parameters:

  1. The database link
  2. The query itself

Example:

$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$query = mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜