Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Prepared语句在非对象上返回bind_param()_Php_Mysql - Fatal编程技术网

Php Prepared语句在非对象上返回bind_param()

Php Prepared语句在非对象上返回bind_param(),php,mysql,Php,Mysql,我试图创建一个简单的api,将视图添加到表中。然后,为了避免SQL注入,我尝试使用预先准备好的语句,但似乎无法使其工作。它不断返回以下错误:(致命错误:对中的非对象调用成员函数bind_param()) 打开警告。您的语法中有一个错误。因此$con->prepare返回false并发出警告 您可以在中找到错误文本。我认为您在这里混合了mysqli和PDO实现。对于mysqli,您应该使用bind_parambindParam和bindValue是PDOs $con = new mysqli('h

我试图创建一个简单的api,将视图添加到表中。然后,为了避免SQL注入,我尝试使用预先准备好的语句,但似乎无法使其工作。它不断返回以下错误:
(致命错误:对中的非对象调用成员函数bind_param())


打开警告。您的语法中有一个错误。因此
$con->prepare
返回
false
并发出警告


您可以在中找到错误文本。

我认为您在这里混合了
mysqli
PDO
实现。对于
mysqli
,您应该使用
bind_param
bindParam
bindValue
PDO
s

$con = new mysqli('host','user','pass','db');
$type = $_GET['type'];
$identifier = $_GET['identifier'];
$news = $_GET['newsid'];

$check = $con->prepare("SELECT * FROM news WHERE news.news_id =? OR news.type =? OR news.identifier=?");
$check->bind_param("iss", $news, $type, $identifier);
$check->execute();


if ($check->fetchColumn() > 0) {

    $add_view = $con->prepare("INSERT INTO views VALUES (:news_id, :identifier, :type, CURRENT_TIMESTAMP())");
    $add_view->bindValue(':news_id', $news);
    $add_view->bindValue(':identifier', $identifier);
    $add_view->bindValue(':ntype', $type);
    $add_view->execute();

}