output_type – wpdb Class

Lorsque je fais un

$wpdb->get_results($querystr, OBJECT);

j’utilise OBJECT comme output_type.

On lire à ce sujet : https://codex.wordpress.org/Class_Reference/wpdb dont un extrait est ici :

OBJECT – result will be output as a numerically indexed array of row objects.
OBJECT_K – result will be output as an associative array of row objects, using first column’s values as keys (duplicates will be discarded).
ARRAY_A – result will be output as a numerically indexed array of associative arrays, using column names as keys.
ARRAY_N – result will be output as a numerically indexed array of numerically indexed arrays.
Since this function uses the $wpdb->query() function all the class variables are properly set. The results count for a ‘SELECT’ query will be stored in $wpdb->num_rows.

Dans le 1er cas

$result = $wpdb->get_results($id_a_virer, OBJECT);

J’obtiens :

[post] => Array
        (
            [0] => Array
                (
                    [ID] => 123992
                )

            [1] => Array
                (
                    [ID] => 123994
                )

            [2] => Array
                (
                    [ID] => 123996
                )

            [3] => Array
                (
                    [ID] => 123998
                )

            [4] => Array
                (
                    [ID] => 124000
                )

        )

Dans le 2ème cas

$result = $wpdb->get_results($id_a_virer, OBJECT_K);

J’obtiens :

[post] => Array
        (
            [123992] => Array
                (
                    [ID] => 123992
                )

            [123994] => Array
                (
                    [ID] => 123994
                )

            [123996] => Array
                (
                    [ID] => 123996
                )

            [123998] => Array
                (
                    [ID] => 123998
                )

            [124000] => Array
                (
                    [ID] => 124000
                )

        )

)

Dans le 3ème cas

$result = $wpdb->get_results($id_a_virer, OBJECT_K);

J’obtiens :

[post] => Array
        (
            [0] => Array
                (
                    [ID] => 123992
                )

            [1] => Array
                (
                    [ID] => 123994
                )

            [2] => Array
                (
                    [ID] => 123996
                )

            [3] => Array
                (
                    [ID] => 123998
                )

            [4] => Array
                (
                    [ID] => 124000
                )

        )

)

Dans le 4ème cas

$result = $wpdb->get_results($id_a_virer, ARRAY_N);
[post] => Array
        (
            [0] => Array
                (
                    [0] => 123992
                )

            [1] => Array
                (
                    [0] => 123994
                )

            [2] => Array
                (
                    [0] => 123996
                )

            [3] => Array
                (
                    [0] => 123998
                )

            [4] => Array
                (
                    [0] => 124000
                )

        )

)

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *