mardi 20 janvier 2015

Error: 'Trying to get property of non-object'

So i'm having this trouble. Errors on lines 3,4,5. This is how i define object properties:



class Article {
//line 3
public $id; // line 4
public $pubDate; // line 5
public $title;
public $content;


And here is my method that gives an error:



public static function getById( $id ) {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT *, UNIX_TIMESTAMP(pubDate) AS pubDate FROM material WHERE id = :id";
$st = $conn->prepare( $sql );
$st->bindValue( ":id", $id, PDO::PARAM_INT );
$st->execute();
$row = $st->fetch();
$conn = null;
if ( $row ) return new Article( $row );
}


I've tried to disable error by using:



error_reporting(0);
@ini_set('display_errors', 0);


But it's only masks the problem, publication still doe's not appear on page. Thank you.


Aucun commentaire:

Enregistrer un commentaire