mysqli insert in php


mysqli insert in php

嗨,我是 Msqli 的新手,因为我现在正在迁移我所有的 mysql 代码。 因为 MySQL 现已弃用,所以我现在有我的连接

    function rlConnection()
{
    global $g_link;
    if( $g_link )
        return $g_link;
    $g_link = mysql_connect( 'localhost', 'username', 'password') or die('Could not connect to server.' );
    mysql_select_db('forum', $g_link) or die('Could not select database.');
    return $g_link;
}
function CleanConnection()
{
    global $g_link;
    if( $g_link != false )
        mysql_close($g_link);
    $g_link = false;
}

我试图插入一些值并给我这个错误

警告:mysqli_query() 期望参数 1 是 mysqli,字符串在

上述错误的代码是

        include("dbconfig.php");
    mysqli_query("SET NAMES 'utf8'");       
    $pid = $_POST['categories'];
    $name=mysql_real_escape_string($_POST['forumname']);
    $description=mysql_real_escape_string($_POST['description']);
    $date = time();
    $locked = 0;
    mysqli_query("INSERT INTO forum (pid, name, description) VALUES ('$pid', '$name', '$description')", rlConnection()  );

我需要一些快速的建议,提前感谢,顺便说一句,对不起我的英语不好。

查看mysqli_query文档。第一个参数应该是 mysqli 链接。

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

从本质上讲,$g_link是:

mysqli_query(rlConnection(), "SET NAMES 'utf8'");

mysqli_query(rlConnection(), "INSERT INTO forum (pid, name, description) VALUES ('$pid', '$name', '$description')");

然后更改连接字符串以使用 mysqli_connect

$g_link = mysqli_connect( 'localhost', 'username', 'password', 'forum')