SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected
大神帮我看一眼谢谢。
try{
$pdo = new PDO("mysql:host-localhost;dbname-xsphpdb",
"root", "123456");
$pdo->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
echo "数据库连接失败:".$e->getMessage();
exit;
}
try{
//使用PDO方法执行语句
$affected_rows = $pdo->exec("insert into t2
(id,username,age,sex) values('4','jianze','22','1');");
echo $affected_rows;
echo $pdo->lastinsertid();
}catch(PDOException $e){
echo "错误".$e->getMessage();
}
MMTTMM
慕姐8265434