• 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 Access A Column In M-M Relationship Table In Laravel

php echo xml documents with header

Sentry on Symfony: how to exclude `NotFoundHttpException`

AJAX call fails with SyntaxError: Unexpected end of JSON input

file_get_contents() without "Http" to access external URL [closed]

Laravel PackageManifest.php: Undefined index: name

How to reset Laravel AuthManager/guards in between API calls in tests?

Installing Composer - Internal Error

Edit product hook WooCommerce

Using PHP to connect to a remote MSSQL database

XDebug not working in VScode for php debugging

How to get an Array value inside an object in an array Php [duplicate]

Smarty: undefined extension class 'Smarty_Internal_Method_Get_Template_Vars'

PHP array stringify

Implode columnar values between two arrays into a flat array of concatenated strings

About Contact Privacy policy Terms and conditions