开发者

Invalid Data Source PHP PDO Mysql

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

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . 开发者_C百科$e->getMessage();
}

$pdo1 = new PDO($dsn, $user, $password);
$pdo1->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth1 = $pdo1->prepare('SELECT pID, lname, fname FROM Professor ORDER BY pID DESC LIMIT 5;');
$sth1->execute(array());
?>

Throws the error:

Uncaught exception 'PDOException' with message 'invalid data source name' in  PDO->__construct('', NULL, NULL) on line 1

Anyone see anything wrong with this?


you have

$dsn = 'mysql:dbname=dbname;host=somehost;

maybe just maybe ...

$dsn = 'mysql:dbname=dbname;host=somehost';

unless this was a mouso when cut-and-pasting the question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜