I made a mistake myself, thank you all

WBOY
Release: 2016-08-04 09:20:52
Original
912 people have browsed it

I made a mistake myself, thank you everyone

This question has been closed, reason: Unable to obtain exact result

Reply content:

I made a mistake myself, thank you everyone

bindParam is a method of PDOStatement. Of course you can’t find it in PDO.

PDOStatement is the return object of PDO::prepare(). I don’t know where to look for the code here. I named the PDO object as $stmt without getting ->prepare() The returned PDOStatement.

<code>
$pdo = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);//先新建一个PDO
$pdo->->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//开启PDO的报错
$sql = 'SELECT * FROM article WHERE id > ?';
try{
    $stmt = $pdo->prepare(sql);//返回的statment的值赋给$stmt
    $stmt -> bindParam(要绑定的占位符的位置, 要绑定的变量 [, 数据类型]);//bindParam()是$stmt的方法而不是$pdo的方法
    $stmt -> execute();//执行sql语句
} catch (PDOException $e) {
        echo 'Execute SQL failed: ' . $e->getMessage();
        exit();
    }
</code>
Copy after login

It should be like this

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!