• 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

Add a custom text for a particular product on specific email notification in Woocommerce

How to give apache permission to write to home directory?

Utf8 encoding issue with Laravel

Laravel csrf token mismatch for ajax POST Request

Additional price based on cart item count in WooCommerce

PHP mail sending empty mails

Form Validation and Submission to database

Select option menu read from database and use it's values

Laravel Database Strict Mode

PHP Warning: Module already loaded in Unknown on line 0

(Laravel) How to delete multiple models including optional relationships?

Add Class in html Dynamically in PHP

Inserting data into SQL Server Db An Invalid direction was specified

how to sort by a custom appended relation to model

PHPExcel export HTML table to xlsx

About Contact Privacy policy Terms and conditions