<?php
header("content-type:text/html;charset=utf-8");
$dbms = "mysql";
$dbhost = "localhost";
$dbuser = "root";
$dbpwd = "";
$dbname = "student";
$dsn = "$dbms:host=$dbhost;$dbname";
try{
$pdo = new PDO($dsn,$dbuser,$dbpwd);
$pdo->query("set names utf8");
$sql = "insert into stu(uid,name,sex,age,grade,class,cre_time) values ('450000','susan','男','23岁','幼儿园','中一班',now())";
$row = $pdo->exec($sql);
echo "影响了".$row."行";
}catch(PDOException $e){
die("出错了:".$e->getMessage());
}
?>
//
stu 表结构
id int(6) 自动增量
uid varchar(8)
name varchar(12) NULL
sex varchar(4) NULL
age varchar(10) NULL
grade varchar(10) NULL
class varchar(6) NULL
cre_time datetime NULL
mod_time datetime NULL
。。。。。
粗心了,$dsn = "$dbms:host=$dbhost;$dbname"; 这里错了
应该是$dsn = "$dbms:host=$dbhost;dbname = $dbname"; 少了dbname=
执行结果显示什么? 没信息? 还是报有错误?