我將mySQL的部分代碼從mySQL遷移到PDO,我似乎無法看到我的代碼出了什麼問題。PHP和PDO - 從MySQL遷移 - 不顯示結果或錯誤
我有一個try/catch語句和錯誤報告,但我什麼都沒有得到。
這裏有人可以看到什麼是錯的?
是有關這個問題的文件是:
db_pdo.php
<?php
// Define connection
$db_host = "localhost";
$db_name = "winestore";
$db_user = "user";
$db_pass = "pass";
$db = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
的search.php
<?php
require_once ("MiniTemplator.class.php");
function getSearch($tableName, $attributeName) {
try {
require ("db_pdo.php");
$query = "SELECT DISTINCT {$attributeName} FROM {$tableName} ORDER BY {$attributeName}";
return $db->query($query);
} catch (PDOException $e) {
echo $e->getMessage();
exit;
}
}
function generatePage(){
$t = new MiniTemplator;
$t->readTemplateFromFile ("search_template.htm");
$rows = getSearch("region", "region_name");
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$t->setVariable('regionName', $row['region_name']);
$t->addBlock("regionName");
}
$rows = getSearch("grape_variety", "variety");
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$t->setVariable('variety', $row['variety']);
$t->addBlock("variety");
}
$rows = getSearch("wine", "year");
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$t->setVariable('minYear', $row['year']);
$t->addBlock("minYear");
}
$rows = getSearch("wine", "year");
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$t->setVariable('maxYear', $row['year']);
$t->addBlock("maxYear");
}
$t->generateOutput();
}
generatePage();
?>
你不力的功能generatePage(){ – 2014-09-02 11:53:41
返回任何@punithasubramaniv可以假定輸出由'$ T-> generateOutput處理()' – 2014-09-02 12:00:14
@GeraldSchneider,你是對的。 – Cheung 2014-09-02 12:06:27