Home  >  Article  >  Backend Development  >  Beginner's question: PDO operations on linux

Beginner's question: PDO operations on linux

WBOY
WBOYOriginal
2016-07-06 13:51:28975browse

I just applied for a student machine recently. I tried to connect to the database on Linux:

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

However, the webpage cannot be connected, and the status code returned is: 500
The local host test connection is successful, and the confirmation code is correct (the account number, password, and database are all correct),

Under linux host, test:

php test.php //Return connection success!

It’s strange, why can the php command be run but the webpage just can’t be displayed?
Is it because there is no PDO extension? If yes, then how do I install it?

Reply content:

I just applied for a student machine recently. I tried to connect to the database on Linux:

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

However, the webpage cannot be connected, and the status code returned is: 500
The local host test connection is successful, and the confirmation code is correct (the account number, password, and database are all correct),

Under linux host, test:

php test.php //Return connection success!

It’s strange, why can the php command be run but the webpage just can’t be displayed?
Is it because there is no PDO extension? If yes, then how do I install it?

Mostly the mysql user permissions are set incorrectly, local access is available, but Yuncheng denies access

$serverIf it is "localhost", why not try changing it to "127.0.0.1"? The two are different.

Statement:
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