• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Having trouble with PDO queries (Notice: Undefined index)

phppdo


PHP Snippet 1:

$row = $resultBySQL->fetchAll(PDO::FETCH_ASSOC);

PHP Snippet 2:

//notice the 'fetch' in place of 'fetchAll'
while ( $row = $resultBySQL->fetch(PDO::FETCH_ASSOC); ) 
{
    $user = new User();
    $user->setUsername($row['username']);

    //...
}

PHP Snippet 3:

$rows = $resultBySQL->fetchAll(PDO::FETCH_ASSOC);

foreach( $rows as $row )
{
    $user = new User();
    $user->setUsername($row['username']);

    //...
} 

Related Snippets

How to get company posts from LinkedIn via API?

How to loop sql table data inside a html table

How to make Canonicals with PHP

Yii2 select2 database exception number of bound variables does not match number of tokens

How can I format this number correctly using PHP?

How to display MySQL table using php and edit it in a web browser

Laravel eloquent update record without loading from database

Facebook PHP SDK - will not logout properly

JQuery content editable div and text box on submit not sending POST

How do I enable error reporting in Laravel?

str_word_count() function doesn't display Arabic language properly

Remove product downloads section in woocommerce email notifications

Handle error for duplicate entries - PHP/MySQL

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

php: command not found Command PhaseScriptExecution failed with a nonzero exit code

About Contact Privacy policy Terms and conditions