Something went wrong there, why can't I add information?
不吃玉米糖
不吃玉米糖 2017-11-10 19:08:30
0
4
1007

<?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','male','23 years old','kindergarten','first class',now( ))";
$row = $pdo->exec($sql);
echo "Affected the ".$row." row";
}catch(PDOException $e){
die("An error occurred:".$e->getMessage());
}
?>

//




stu table structure

id int(6) automatic increment

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

不吃玉米糖
不吃玉米糖

reply all(2)
不吃玉米糖

. . . . .

I was careless, $dsn = "$dbms:host=$dbhost;$dbname"; This is wrong


It should be $dsn = "$ dbms:host=$dbhost;dbname = $dbname"; missing dbname=

猪哥

What does the execution result show? No information? Or is there an error in the report?

  • reply Thank you, I found it. I accidentally missed dbname=.
    不吃玉米糖 author 2017-11-13 20:42:46
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template