My $query->fetch() doesn't work

Posted by Tae on Stack Overflow See other posts from Stack Overflow or by Tae
Published on 2011-03-08T22:51:33Z Indexed on 2011/03/10 0:10 UTC
Read the original article Hit count: 95

Filed under:
|

Question edited following the comments. It still doesn't work.

Hi there,

I'm trying to learn how PDO works, but my script:

$database = new PDO('mysql:host=localhost;dbname=***', '***', '***');
$query = $database->prepare("SELECT nombre, 
                                    tecnica,
                                    tamanno,
                                    estado FROM obra WHERE anno = ?");
$query->execute(array('2009'));
while ($item = $query->fetch(PDO::FETCH_ASSOC)) {
    $item['nombre'];
}

Prints nothing. If I do:

var_dump($query->fetch())

I get bool(false). After reading lots of examples I can't figure out what I'm doing wrong.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about php

Related posts about pdo