1 <?php 2 header("Content-type: text/html; charset=utf-8"); 3 //设置中国时区 4 date_default_timezone_set('PRC'); 5 6 $dsn="mysql:host=127.0.0.1;port=3306;dbname=test;charset=utf8"; 7 $username="root"; 8 $password="root"; 9 10 $pdo=new PDO($dsn,$username,$password); 11 12 // $sql="INSERT INTO student VALUES(NULL,'李鬼','1',36,default,3000,300,'山东')"; 13 // $lines=$pdo->exec($sql); 14 // var_dump($pdo); 15 // $sql="INSERT INTO student(name,salary,bonus,city) VALUES (:name,:salary,:bonus,:city)"; 16 $sql="INSERT INTO student(name,salary,bonus,city) VALUES (?,?,?,?)"; 17 $PDOStatement=$pdo->prepare($sql); 18 $PDOStatement->bindValue(1,'阮小七'); 19 $PDOStatement->bindValue(2,4000); 20 $PDOStatement->bindValue(3,900); 21 $PDOStatement->bindValue(4,'山东'); 22 23 $PDOStatement -> execute(); 24 25 // echo "行数:{$lines}"; 26 echo "Game Over";
标签:pdo,city,bonus,---,PDOStatement,sql,php,bindValue From: https://www.cnblogs.com/hnqyliu/p/17331333.html