• 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

Magento 2 - Controller returning blank page

PHP array slice from position + attempt to return fixed number of items

How to solve Duplicate entry '0' for key 'PRIMARY' in Wordpress?

Symfony - "framework.test" config is not set to true

phpseclib 2.0 can not use Composer to create autoload

Which is faster php date functions or carbon?

Set quantity minimum, maximum and step at product level in Woocommerce

Problems getting instance of UploadedFile in Yii2

Pass a select with mysqli_fetch_row to a table

How do I truncate a decimal in PHP?

CONCAT columns with Laravel 5 eloquent

Getting output of MS stored procedure on php call

using random function but it's displaying duplicates

How do I upload a laravel project on cPanel shared hosting?

Increase value by 1 on button click

About Contact Privacy policy Terms and conditions