PDO无法在Wamp服务器上的php中工作 [英] PDO Not working in php on wamp server

查看:78
本文介绍了PDO无法在Wamp服务器上的php中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临使用PDO将数据导入数据库的困难.插入在我使用mysql_connect/mysql_query时有效,所以我确定这与PDO有关,我做的不好:

I am facing difficulty getting data into my database using PDO. The insertion works when I use mysql_connect/mysql_query though, so I am sure it's something about PDO I am not getting right:

$db = new PDO("mysql:host=localhost;dbname=XXXXXX","root","");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
    $query= "INSERT INTO tableC VALUES ('1111','2222','XX YY','ERTY','33');";
    $result = $conn ->prepare($query);
    $result ->execute();
} catch {
    echo "PDO error:" . $exception->getMessage();
}

要点:我正在使用PHP并连接到WAMP服务器. PHP版本是5.3.13.我还检查了我的查询是否有效.

Couple of points: I am using PHP and connecting to WAMP server. PHP version is 5.3.13. I have also checked that my query works.

推荐答案

您正在使用$conn->,就像使用$db进行连接一样,因此下面的代码段

You are using $conn-> where as you are using $db for connection so the below snippet

$conn ->prepare($query);

应写为

$db->prepare($query);


此外,您从哪里获得的$exception?您的catch语句应类似于


Also, where did you got $exception from? Your catch statement should look like

catch(PDOException $exception) {

}

这篇关于PDO无法在Wamp服务器上的php中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆