p; /* $insert->execute(array(null,'凯撒','caesar@gmail.com','90',$time)); */
$insert->execute(array(null,'凯撒','caesar@gmail.com','90',$time));
$count=$insert->rowCount();
echo "<br />查询执行完毕!改变的行数为:".$count;
$sql=null;
?>
命名参数绑定方式代码如下:
<?php
header('Content-Type:text/html; charset=utf-8');
require 'config.php';
$sql="INSERT INTO grade (id,name,email,point,regdate) VALUE (:id, :name, :email, :point, :regdate)";
$insert=$DB->prepare($sql);
$time=date('Y-m-d H:i:s',time()+(8*60*60));
//第一种绑定方式
/* $insert->bindValue("id", null);
$insert->bindValue("name", 'caesar');
$insert->bindValue("email", 'caesar@gmail.com');
$insert->bindValue("point", 60);
$insert->bindValue("regdate", $time); */
//第二种绑定方式
/* $insert->bindParam("id", $id);
$insert->bindParam("name", $name);
$insert->bindParam("email", $email);
$insert->bindParam("point", $point);
$insert->bindParam("regdate", $regdate);
$id=null;
$name="凯撒";
$email="caesar@e.com";
$point=65;
$regdate=$time; */
//第三种绑定方式
$insert->execute(array('id'=>null,'name'=>'alice','email'=>'alice@e.com','point'=>90,'regdate'=>$time));
$count=$insert->rowCount();
echo "<br />查询执行完毕!改变的行数为:".$count;
$sql=null;
?>
预处理批量查询,分别采用2种占位符,代码如下:
<?php
header('Content-Type:text/html; charset=utf-8');
require 'config.php';
$DB-