Re: PDO Error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yes, you're right. It's false

This dont't work too.

foreach ($dbh->query('SELECT * FROM words') as $row) {
   echo $row['word'] . "<br>";
}

But this works
$stmt = $dbh->prepare('select * from words');
$stmt->execute();

$rows = $stmt->fetchAll();

echo count($rows) . "<br><br>";




"Marek Kilimajer" <lists@xxxxxxxxxxxxx> escreveu na mensagem 
news:42D79837.7090704@xxxxxxxxxxxxxxxx
> Holografix wrote:
>> print_r($stmt) prints nothing. print($stmt) print nothing too.
>>
>> I checked errorCode() and it prints 0000.
>
> Then it seems $stmt is false. var_dump() is more verbose about it.
>
>>
>>
>> "Marek Kilimajer" <lists@xxxxxxxxxxxxx> escreveu na mensagem 
>> news:42D793E1.70906@xxxxxxxxxxxxxxxx
>>
>>>Holografix wrote:
>>>
>>>>Hi Marek
>>>>
>>>>It's print_r($row), not print_r($stmt) ;)
>>>
>>>That's what I'm asking - If you put print_r($stmt) in that line, what 
>>>does it print?
>>>
>>>
>>>>
>>>>
>>>>"Marek Kilimajer" <lists@xxxxxxxxxxxxx> escreveu na mensagem 
>>>>news:42D75E0F.8020203@xxxxxxxxxxxxxxxx
>>>>
>>>>
>>>>>Holografix wrote:
>>>>>
>>>>>
>>>>>>Hi. When using this example from 
>>>>>>http://netevil.org/talks/index.php?t=pdo&s=20, the site of pdo's 
>>>>>>author I have this error:
>>>>>>
>>>>>>Fatal error: Call to a member function fetchAll() on a non-object in 
>>>>>>/www/home/testes/pdo_my1.php on line 17
>>>>>>
>>>>>>
>>>>>>$dbh = new PDO('mysql:host=localhost;dbname=dbtest', 'user', 'pass');
>>>>>>$stmt = $dbh->query("SELECT * FROM foo");
>>>>>
>>>>>what does print_r($stmt); print here?
>>>>>
>>>>>
>>>>>
>>>>>>$rows = $stmt->fetchAll();
>>>>>>$count = count($rows);
>>>>>>foreach ($rows as $row) {
>>>>>>   print_r($row);
>>>>>>}
>>>>>>$stmt = null;
>>>>>>
>>>>>>Wht's wrong with the example?
>>>>>>
>>>>>>Greetings
>>>>>>holografix
>>>>>>
>>>>
>> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux