-2

I'm getting this error only when I try connect to my localhost, but if i test on my web host, everything is running perfect.

The error i get is pointing on my $query = $dbh->query("SELECT * FROM video");

<?php
    $query = $dbh->query("SELECT video_img FROM video");
        while($r = $query->fetch(PDO::FETCH_OBJ))   {

            echo $r->video_title;

        }

?>

db connection

<?php

$user   =   "root";
$pass   =   "";

try {
    $dbh = new PDO('mysql:host=localhost;dbname=streaming', $user, $pass);
    foreach($dbh->query('SELECT * from video') as $row) {
        //print_r($row);
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?> 

Any tips :)?

Thanks

Dymond
  • 2,158
  • 7
  • 45
  • 80

1 Answers1

1

Looking at the codes you posted, $dbh doesn't make sense since no PDO connection has be initialized:

Second, you are selecting column video_img, then accessing/fetching $r->video_title. This doesn't make sense also:

$dbh = new PDO('mysql:host=localhost;dbname=DATABASE_NAME', 'username', 'password');
$query = $dbh->query("SELECT video_img FROM video");
while($r = $query->fetch(PDO::FETCH_OBJ))   {
    echo $r->video_img;
}
Kevin
  • 41,694
  • 12
  • 53
  • 70
  • I just updated with my db connection. And the selection video_img was my bad, I did not double check the query before I posted. corrected now. – Dymond Nov 28 '14 at 12:02