What am I doing wrong with handling that global with the mysqli_query? [duplicate]
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:
- The database link
- The query itself
Example:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$query = mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");
精彩评论