Jump to content

Sluke

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Sluke's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sluke

    pgsql via PDO

    Hi I've been trying to connect and query pgsql through PDO but can't seem to get very far. I have a table consisting of the following: id, title, owner, post, editdate, createdate, deleted When I try to run a simple query I don't get any output whatsoever <?php try { $db = new PDO("pgsql:host=localhost;dbname=slukedb",blank,blank); $sql = "SELECT title, owner, post, createdate FROM news_posts"; Foreach ($db->query($sql) as $row) { echo $row['title'] . ' - ' . $row['owner'] . ' - ' . $row['post'] . ' - ' . $row['createdate'] . '<br />'; } $db = null; } catch (PDOException $e) { echo $e->getMessage(); } ?> This is given as an example of querying using PDO by almost all sites I've been to. If I try the following I can get a bit further: <?php try { $db = new PDO("pgsql:host=localhost;dbname=slukedb",blank,blank); $sql = "SELECT title, owner, post, createdate FROM news_posts"; $stmt = $db->query($sql); $result = $stmt->fetch(PDO::FETCH_ASSOC); foreach ($result as $row) { echo echo $row['title'] . ' - ' . $row['owner'] . ' - ' . $row['post'] . ' - ' . $row['createdate'] . '<br />'; } $db = null; } catch(PDOException $e) { echo $e->getMessage(); } ?> But it'll only display the first row in the table. Thank you for your help
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.