<?php header("Content-type: text/html; charset=utf-8"); //设置中国时区 date_default_timezone_set('PRC'); $dsn="mysql:host=127.0.0.1;port=3306;dbname=test;charset=utf8"; $username="root"; $password="root"; $pdo=new PDO($dsn,$username,$password); // $sql="INSERT INTO student VALUES(NULL,'李鬼','1',36,default,3000,300,'山东')"; // $lines=$pdo->exec($sql); // var_dump($pdo); // $sql="INSERT INTO student(name,salary,bonus,city) VALUES (:name,:salary,:bonus,:city)"; $sql="INSERT INTO student(name,salary,bonus,city) VALUES (?,?,?,?)"; $PDOStatement=$pdo->prepare($sql); $PDOStatement->bindValue(1,'孙二娘'); $PDOStatement->bindValue(2,6000); $PDOStatement->bindValue(3,900); $PDOStatement->bindValue(4,'山东'); $PDOStatement -> execute(); // echo "行数:{$lines}";
标签:city,bonus,占位,pdo,插入,PDOStatement,sql,bindValue From: https://www.cnblogs.com/hnqyliu/p/17322184.html