How to fix: Warning: mysqli_query() expects parame

2019-09-30 02:34发布

问题:

I'm trying to install Arfooo on my host.

First I got a warning about:

Deprecated: mysql_connect()

After fixing that, now I get this error:

function executeQueryWithPrefix($sql, $tablesPrefix)
{
    $sql = str_replace("CREATE TABLE `", "CREATE TABLE `" . $tablesPrefix, $sql);
    $sql = str_replace("INTO `", "INTO `" . $tablesPrefix, $sql);

    //echo $sql."<br>";

    return mysqli_query($sql);
}

function dbConnect($server, $user, $pass, $dbName)
{

    /* install database with prefixed tables */

    mysqli_connect($DB_HOST, $user, $pass, $dbName);
    //mysql_connect($server, $user, $pass) or die('could not connect to mysql');;

    mysqli_query($dbName, 'CREATE TEMPORARY TABLE `table`');
    //mysql_query('create database IF NOT EXISTS ' . $dbName);

    mysqli_select_db($dbName) or die('could not select database');
}

Please help! Thanks!

回答1:

$link = mysqli_connect($DB_HOST, $user, $pass, $dbName);

mysqli_query($link, 'CREATE TEMPORARY TABLE `table`');

With mysqli you need to save the connection in variable and provide that for every time you use mysqli.

EDIT: generally: You need to provide the connection for every mysqli-related function you use.



标签: php sql mysqli