除非使用类似databasename.tablename,否则PHP PDO select语句不起作用

时间:2014-01-27 13:28:55

标签: php mysql pdo

我的SELECT语句看起来像这样:

$db_Host = "localhost"; 
$db_Username = "neparc";  
$db_Pass = "***************";  
$db_Name = "nepareptileclub"; 

try
{
    $db = new PDO ('mysql:host = '.$db_Host.' ; dbname = '.$db_Name , $db_Username, $db_Pass);
    $db -> setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $result = $db -> query("SELECT stateinital FROM states");
    while($row = $result -> fetch(PDO::FETCH_ASSOC))
    {
        echo $row['stateinital'] . "<br />";
    }
}
catch(PDOException $e)
{
    echo "Error: " . $e -> getMessage() . ".";
}

但是如果我将select语句更改为以下语句就可以了:

$result = $db -> query("SELECT stateinital FROM nepareptileclub.states");

0 个答案:

没有答案