• 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

Don't show recurring price for WooCommerce subscriptions worth 0$

PHP Get value from JSON [duplicate]

Testing subscription renewals on Stripe

Google Calendar API batch request PHP

PHP | "The requested PHP extension bcmath is missing from your system."

Wordpress wpdb->delete issue

Display the WooCommerce product price inside a custom function

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

Python - Include another Python script

"Unable to load dynamic library 'pdo_sqlsrv.so' "Cenos7 PHP7.2.10

Adding one microsecond to Datetime object in PHP

How to Generate PDF invoice to XML format using mPDF

Laravel Blade checkbox not checked

Must be of the type array, null given,

How to retrieve Active Directory group policy maximum password age using LDAP

About Contact Privacy policy Terms and conditions