<?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
不吃玉米糖2017-11-13 20:41:55
。 。 。 。 。
粗心了,$dsn = "$dbms:host=$dbhost;$dbname"; 這裡錯了
應該是$dsn = "$ dbms:host=$dbhost;dbname = $dbname"; 少了dbname=