• 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

Can I write PHP code across multiple lines per statement?

get data-value with variable value

PHP file_get_contents function

dompdf and img tag, image wont show

How to show selected value using javascript in laravel

Not able to access model in the controller mautic

How to find the date a user created their Google account

Vimeo API: how to save a vimeo into a subfolder?

Toggle between a textbox and a select using PHP

How to average columns of data from multiple, flat arrays?

Laravel no logout option from menu after successfull login

Undefined variable in Laravel 8 project (php 7.4)

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

Transpose multidimensional array and join values with commas

PHP's array_map including keys

About Contact Privacy policy Terms and conditions