php - MySQL returns data twice -


i have following code, simplified heavily while trying bottom of this:

<?php   $db_host   = $_env['database_server'];   $db_pass   = 'dummypassword';   $db_user   = 'user';   $db_name   = 'database';   $db_char   = 'utf8';    $db = new pdo("mysql:host=$db_host;dbname=$db_name;charset=$db_char", $db_user, $db_pass);   $db->setattribute(pdo::attr_errmode, pdo::errmode_exception);    $email = 'david@example.com';    if (!empty(trim($email)))     {       $sql = 'select * staff';       $query = $db->prepare($sql);       $query->execute();       $results = $query->fetchall();        echo '<pre>';       print_r($results);       echo '</pre>';     } ?> 

when run this, query works fine , no errors. is:

array (     [0] => array         (             [staff_id] => 1             [0] => 1             [staff_org] => 1             [1] => 1             [staff_email] => david@example.com             [2] => david@example.com             [staff_password] => hashyhashy             [3] => hashyhashy             [staff_first_name] => david             [4] => david             [staff_start_date] => 2014-03-17             [7] => 2014-03-17             [staff_leave_date] =>              [8] =>          ) ) 

personally don't remember ever seeing return data twice (i.e. named key, , again without). question this... have lost mind , how results mysql have been returned? or have done make this?

you getting both numeric zero-indexed key , associative key. if need associative array, can do:

$results = $query->fetchall(pdo::fetch_assoc); 

and if want numeric keys, do:

$results = $query->fetchall(pdo::fetch_num); 

check manual on fetch() more details.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -