• 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

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

Laravel insert dynamic input values with radio button

How do I pass the dynamic output of a php variable or php function to a CSS variable?

How to set time with DateTime modify?

Custom post type single page not working

Woocommerce redirect after add-to-cart error

How can I get user id from session in javascript?

Move a child array to parent array and change parent/child name

PHP usort() order in case of equality

Unable to run composer install

Distribute array row data to make multiple new rows

Why isn't my PHP exception working?

Fetch files from next cloud storage and display in Laravel website

Server-sent events in PHP (without echo or print)

PHP: How to raise number to (tiny) fractional exponent?

About Contact Privacy policy Terms and conditions