初学者的问题:linux上的PDO操作

WBOY
Release: 2016-07-06 13:51:28
Original
939 people have browsed it

最近刚申请的学生机,我试着在linux上连接一下数据库:

<code>try {
    $conn = new PDO("mysql:host=$server;dbname=$db",$user,$pass);
    echo "connection success!";
}
catch(PDOException $e) {
    echo $e->getMessage();
}</code>
Copy after login
Copy after login

可是网页连接不上,返回状态码:500
本地主机测试连接成功,确认代码没有错误(账号,密码,数据库都正确),

在linux 主机下,测试:

php test.php //返回 connection success!

很奇怪,为什么php命令可以运行,网页就是出不来呢?
是因为没有PDO扩展吗? 如果是,那么我该如何安装呢?

回复内容:

最近刚申请的学生机,我试着在linux上连接一下数据库:

<code>try {
    $conn = new PDO("mysql:host=$server;dbname=$db",$user,$pass);
    echo "connection success!";
}
catch(PDOException $e) {
    echo $e->getMessage();
}</code>
Copy after login
Copy after login

可是网页连接不上,返回状态码:500
本地主机测试连接成功,确认代码没有错误(账号,密码,数据库都正确),

在linux 主机下,测试:

php test.php //返回 connection success!

很奇怪,为什么php命令可以运行,网页就是出不来呢?
是因为没有PDO扩展吗? 如果是,那么我该如何安装呢?

多半是mysql用户权限设置不正确, 本地可以访问, 而运程拒绝访问

$server如果是"localhost"的话,不妨改成"127.0.0.1"试试?两者是不一样的。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!