如何解决:警告:mysqli_query()期望参数1是mysqli?

时间:2016-04-19 07:04:32

标签: php sql mysqli

我正在尝试在我的主机上安装Arfooo。

首先我收到警告:

Deprecated: mysql_connect()

修好后,现在我收到了这个错误:

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');
}

请帮忙! 谢谢!

1 个答案:

答案 0 :(得分:1)

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

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

使用mysqli,你需要在变量中保存连接,并在每次使用mysqli时提供连接。

编辑:通常:您需要为您使用的每个与mysqli相关的函数提供连接。