PDOStatement::getColumnMeta returns original table name instead of view name
Asked Answered
M

1

9

I am using the CakePHP framework. When returning the results of a query, the framework calls the "experimental" PDOStatement::getColumnMeta to "arrayify" the data when it comes back from the database. However, there are mixed results depending on the query.

There are times when the array of data comes back as expected where all columns are associated to the name of the view. Other times, the data comes back mixed, where some of the data sits in an array associated with the original table that corresponds to the view.

// correct
Array(
[MyInstall] => Array
    (
        [id] => a6d1342a-7b4d-11e1-8397-60195b7d6275
        [user_id] => dc038c9e-7b4b-11e1-8397-60195b7d6275
        [script_id] => 057de1e0-7b48-11e1-8397-60195b7d6275
        [path] => 
        [url] => 
        [created] => 2009-06-15 12:43:30
        [version] => 3.2.1
        [admin_url] => wp-admin
        [name] => WordPress
        [icon] => icon_WordPress.gif
   )
)

//incorrect
Array(
[MyInstall] => Array
    (
        [id] => c71a2368-7b4d-11e1-8397-60195b7d6275
        [user_id] => dc038c9e-7b4b-11e1-8397-60195b7d6275
        [path] => 
        [url] => 
        [created] => 2011-11-07 22:26:38
        [version] => 3.2.1
        [admin_url] => wp-admin
  )

[Script] => Array
  (
        [script_id] => 057de1e0-7b48-11e1-8397-60195b7d6275
        [name] => WordPress
        [icon] => icon_WordPress.gif
  )
)

The way the results are built is from the results of the PDOStatment::getColumnMeta. Here is what a sample result of getColumnMeta looks like:

Array
(
    [native_type] => STRING
    [pdo_type] => 2
    [flags] => Array
        (
            [0] => not_null
        )

    [table] => MyInstall
    [name] => id
    [len] => 108
    [precision] => 0
)

Any suggestions on how I can get this same information using PDO for MySQL? Or is there another solution to this problem?

BTW: I already filed a bug with the PHP folks on this.

Monohydric answered 1/4, 2012 at 5:33 Comment(1)
I discovered this issue is related to using a combination of view name Aliases combined with Where clause issues. (see the bug in the OP). Still waiting for a response from the PHP dev.Monohydric
U
2

As it turns out, this is a now known bug in MySQL: http://bugs.mysql.com/bug.php?id=66794, still pending at the time of writing.

Ulaulah answered 29/12, 2012 at 19:22 Comment(1)
Perhaps your ticket at PHP should link to the MySQL bug tracker?Ulaulah

© 2022 - 2024 — McMap. All rights reserved.