Why isnt this pulling anything? Php/mysql
<?php
if($sth1->rowCount() > 0) {
开发者_JS百科$row = $sth1->fetch(PDO::FETCH_ASSOC);
echo "<div> <h2>{$row1['prefix']} {$row1['code']}</h2></div>";
} else {
echo "No results.";
}
unset($sth1);
?>
<?php
$username = "###";
$password = "####";
$pdo1 = new PDO('mysql:host=####;dbname=####', $username, $password);
$pdo1->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth1 = $pdo1->prepare('SELECT pID, lname, fname FROM Professor ORDER BY pID DESC LIMIT 10;;');
$sth1->execute(array());
?>
Result: Just a blank page, no error.
I hope your two code blocks are the other way around in your php file...
Apart from that you are using $row1
in your echo
statement but your data is stored in variable $row
. The blank page would then be a div
with an empty h2
.
Variable $sth1 isn't set, when it is used in line 2. Try this one (changed attributes/name of table):
ini_set("display_errors", TRUE);
error_reporting(E_ALL);
$pdo1 = new PDO('mysql:host=localhost;port=8889;dbname=test', '**', '**' );
$pdo1->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth1 = $pdo1->prepare('SELECT name, title FROM tab1 ORDER BY name DESC LIMIT 10');
$sth1->execute(array());
if($sth1->rowCount() > 0) {
$row = $sth1->fetch(PDO::FETCH_ASSOC);
echo "<div> <h2>{$row['name']} : {$row['title']}</h2></div>";
} else {
echo "No results.";
}
精彩评论