'HTTP 500 Internal Server error with PDO [duplicate]
I am getting Internal Server Error when I use the following code. Do I have to change any configuration? I am using PHP version 5.2.6. I couldn't find any documentation about this issue. Please let me know. Thank you.
try {
$dbh = new PDO($db_host1, $db_username, $db_password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Solution 1:[1]
You have to pass DSN as first parameter of PDO constructor.
try {
$dsn = "mysql:dbname=testdb;host={$db_host1}";
$dbh = new PDO($dsn, $db_username, $db_password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Solution 2:[2]
I had the same 500 error after installing php-mysql.
Solution:
Restart the webserver.
I forgot to restart my webserver, which resolved the problem for me.
Apache error log said :
> PHP Fatal error: Uncaught Error: Undefined class constant
> 'MYSQL_ATTR_INIT_COMMAND' in /var/www/html/[...].php:8 Stack trace:
> #0 /var/www/html/[...].php(27): myFunction()
> #1 {main} thrown in /var/www/html/[...].php on line 8, referer: http://localhost/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugene Manuilov |
| Solution 2 | Starsky |
