<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <?php /*//定义数据源 $dsn = "mysql:dbname=tt;host=localhost"; //造PDO对象 $pdo = new PDO($dsn,"root","123"); //sql语句 $sql = "select * from info"; //准备执行sql语句 $ss = $pdo->prepare($sql); //执行语句 if($ss->execute()) { //print_r($ss->fetch()); var_dump($ss->fetchColumn(1)); } else { echo "失败"; }*/ $pdo = new PDO("mysql:dbname=tt;host=localhost","root","123"); $sql = "insert into info value(?,?,?,?,?)"; $sa = $pdo->prepare($sql); /*//给sql语句分配变量 $sa->bindParam(1,$code); $sa->bindParam(2,$name); $sa->bindParam(3,$sex); $sa->bindParam(4,$nation); $sa->bindParam(5,$birthday); //给变量赋值 $code = "p110"; $name = "啊"; $sex =true; $nation = "n002"; $birthday ="1222-11-11"; //执行语句 $sa->execute();*/ //执行sql语句简便方法 $sa->execute(array("p111","按时","true","n002","1111-11-11")); ?> </body> </html>