Home>

Hello everyone, I need to change the type of array derived from the database.

PHP code:

$ db= new pdo ('mysql: host= localhost; dbname= dpk', 'user', '1234');
$ db->
Exec ("Set Names UTF8");
$ Query= $ db->
Prepare ("SELECT Entry_ID, Starred from` WP_WPForms_entries` Where form_id= 1656 ");
$ Query->
Execute ();
$ res= $ query->
fetchall ();

Variable $ Res:

Array
(
    [0]= >
 Array.
        (
            [entry_id]= >
 106.
            [0]= >
 106.
            [STARRED]= >
 0.
            [1]= >
 0.
        )
    [1]= >
 Array.
        (
            [entry_id]= >
 121.
            [0]= >
 121.
            [STARRED]= >
 0.
            [1]= >
 0.
        )
)

And it is necessary that the variable $ RES has this output view:

Array
(
    [0]= >
 Array.
        (
            [entry_id]= >
 106.
            [STARRED]= >
 0.
        )
    [1]= >
 Array.
        (
            [entry_id]= >
 121.
            [STARRED]= >
 0.
        )
)

i.e., as far as I know, this can be made by setting the correct parameter in Prepare () or Execute () or Fetchall (). I did not understand the documentation and as it is called I do not know.

$ Mode= PDO :: Fetch_assoc?

Akina2021-08-25 08:00:43

@Akina, this is what I was looking for, thank you.

freestyle_HD2021-08-25 08:08:08

You can, by the way, write an answer, I could not find such a question

Ипатьев2021-08-25 08:21:39

But as for me, in this case there will be a lot of kosherner PDO :: fetch_key_pair

Ипатьев2021-08-25 08:30:11

@ Ipatiev then it will receive ([106]=>0, [121]=>0), that he is unlikely to be required ...

Akina2021-08-25 08:54:47