Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO::FETCH_ASSOC What is about PDO::FETCH_ARRAY?

Tags:

php

pdo

<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
?>

The above example will fetch all of the remaining rows in the result set and output something similar to:

Array
(
    [0] => Array
        (
            [NAME] => pear
            [0] => pear
            [COLOUR] => green
            [1] => green
        )

    [1] => Array
        (
            [NAME] => watermelon
            [0] => watermelon
            [COLOUR] => pink
            [1] => pink
        )

)

Is there any option to get a result like the one my_sql_fetch_array returns, which looks like this:

Array
(
    [0] => Array
        (

            [0] => pear
            [1] => green
        )

    [1] => Array
        (

            [0] => watermelon             
            [1] => pink
        )

)
like image 203
sophie Avatar asked Feb 20 '23 03:02

sophie


1 Answers

From http://php.net/manual/en/pdostatement.fetch.php

$result = $sth->fetchAll(PDO::FETCH_NUM);
like image 120
Musa Avatar answered Mar 03 '23 19:03

Musa