• 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

Zig-zag scan an N x N array

Laravel Blade checkbox not checked

Adding custom body class to the custom archive pages

Adding one microsecond to Datetime object in PHP

How to change 'users' auth table and use another instead Laravel

Split array into 4-element chunks then implode into strings

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

Not able to access model in the controller mautic

Coinpayments create_transaction "ERROR: Invalid command!"

Symfony 4: how to allow dynamic values for array nodes in bundle configuration?

display WooCommerce “Add to cart” button with short-code [add_to_cart ] dynamically

Group rows by column and sum another column within groups [duplicate]

Match csv filenames to table names and import

auth pages not getting css in laravel

Creating command to backup MySql database in Laravel

About Contact Privacy policy Terms and conditions