Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dsn = 'pgsql:dbname=test;host=localhost;';
- $user = 'postgres';
- $password = '?????';
- try {
- $dbh = new PDO($dsn, $user, $password);
- $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo "Connected";
- } catch(PDOException $e) {
- echo 'Connection failed: ' .$e->getMessage();
- }
- // /*
- $calories = 150;
- $color = "red";
- $sth = $dbh->prepare('SELECT name, color, calories FROM fruit');
- //$sth->bindValue(1, $calories, PDO::PARAM_INT);
- //$sth->bindValue(2, $color, PDO::PARAM_STR);
- $sth->execute();
- //$test = $sth->fetch(PDO::FETCH_OBJ);
- $test = $sth->fetchAll();
- //print_r($test);
- // */
- ?>
- <html>
- <head>
- <style type="text/css">
- table, th, td {
- border: 1px solid black;
- }
- </style>
- </head>
- <body>
- <table>
- <thead>
- <tr>
- <th>Test table</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><?php print_r($test); ?></td>
- </tr>
- </tbody>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement