• 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

Unable to Edit config.inc.php

WordPress - Dynamically add user ID to the end of a URL

Handling expired token in Laravel

Passing a boolean value from checkbox in Laravel form

How to extract price from given url using Xpath?

Redis Command To Sort Keys

Split comma separated value from table column into rows using mysql?

Limit WooCommerce products in cart only from one custom taxonomy

How can i call a function that executes an fpdf based on the choice of a form selector?

Laravel query builder binding parameters more than once

Laravel Command Schedule Not Working Properly

shell errors running php exec

Laravel Passport - Not able to get token string in response?

Shopify password update using Shopify API

how can I set a session variable in Drupal 8 and get it in a php script?

About Contact Privacy policy Terms and conditions