I have database named testDB and one table test_tbl in it with three fields ID, User, Pass in PostgreSQL database on Mac OS X.
I am using following php code to fetch results from the table.
<?php
try {
$dbuser = 'postgres';
$dbpass = 'test123';
$dbhost = 'localhost';
$dbname='testDB';
$connec = new PDO("pgsql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
} catch (PDOException $e) {
echo "Error : " . $e->getMessage() . "<br/>";
die();
}
$sql = 'SELECT ID, User, Pass FROM test_tbl ORDER BY ID';
foreach ($connec->query($sql) as $row) {
print $row['ID'] . " ";
print $row['User'] . "-->";
print $row['Pass'] . "<br>";
}
It's raising following error:
Warning: Invalid argument supplied for foreach() in /Users/nikko/Sites/pg_conn2.php on line 12
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTIONfor your connection options ?