• 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

Custom API and cunsuming in php?

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

Cannot retrieve error message using Symfony HttpClient if the response is not "ok"

Reload parent page after submit in iframe

PHP function Not Working As Expected From functions.php Include File

Live search query using JS and PHP for QA forum

Jquery DataTables: Data not displaying in table via Ajax

Override default Auth routes in Laravel 7

Object of class stdClass could not be converted to string error

Cannot pass null argument when using type hinting

How to test laravel controller method?

How can I easily switch between PHP versions on Mac OSX?

How to use functions that are declared in snippets in Evolution CMS (Modx) in an external PHP Script?

Adding the custom page with add_menu_page function on Wordpress

Add restriction to WooCommerce coupons by allowed user ID

About Contact Privacy policy Terms and conditions