• 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 can i call a function that executes an fpdf based on the choice of a form selector?

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

Array to string conversion

PHP: convert all UTF-8 characters to HTML entities

Transpose and flatten multiple rows of array data [duplicate]

Updating and Synchronizing Woocommerce Subscriptions to Custom Date

Unable to match results of php hash_hmac() and coldfusion hmac()

Select option from dropdown menu with PHP and mySql

PhP how to calculate moments with variables rows

PHP DOTENV unable to load env vars

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

Reducing authentication calls on external API (Laravel 5.6)

Multiple order by in WooCommerce

Check if a string contain multiple specific words

Composer Warning: openssl extension is missing. How to enable in WAMP

About Contact Privacy policy Terms and conditions