开发者

Weird PHP PDO Error

<?php
require_once('inc/dbc1.php');
$dsn = 'mysql:dbname=somedb;host=somehost';
$user = 'someuser';
$password = 'somepass';

$pdo1 = new PDO($dsn, $user, $password);
$pdo1->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTI开发者_运维百科ON );
$sth1 = $pdo1->prepare('SELECT pID, lname, fname FROM Professor ORDER BY pID DESC LIMIT 5;');
$sth1->execute(array());
?>

Fatal error: Class 'PDO' not found on line 7

Line 7 is: $pdo1 = new PDO($dsn, $user, $password);

Why does this give this error and how do I fix it? All I'm trying to do is connect with the credentials and run that query


$pdo1 = new PDO($dsn, $user, $password); PHP is looking for the class PDO on this line, I'm assuming it is in the file you included. Check to make sure it's the right file. PHP can't find the class definition. Maybe, make sure it is spelled correctly too.


If you're using a newer PHP version, you might have to prefix global classes with the global namespace identifier: "\"

So it would become: $pdo1 = new \Pdo(...);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜