[wp-hackers] $wpdb: columns with digit names

Alexander Concha alex at buayacorp.com
Thu Apr 5 13:14:09 UTC 2012


On Wed, Apr 4, 2012 at 10:21 PM, Alexander Höreth <a.hoereth at gmail.com> wrote:
> Hey there,
> have been hanging here searching for the problem since an hour at least.
> Wrote quite some code and than it didn't work. Didn't even give me an error:
>
> It displayed all columns of my new mysql database table but the last two.
> Their names were 1 and 2.
> What really freaked me out was they didn't show up this way:
>
> print_r( $wpdb->get_row( "SELECT * FROM " . DBNAME . " WHERE id = '" .
> $target. "';", 'ARRAY_A' ) );
>
> But this way:
>
> print_r( $wpdb->get_col_info('type') );
>
> Tested it using SELECT 1, 2 [...] as well, no effect.
> I didn't find anything similar online, so I think maybe it is a Wordpress
> Bug!?

The WP DB class uses mysql_fetch_object to retrieve each row
(<http://core.trac.wordpress.org/browser/trunk/wp-includes/wp-db.php#L1124>).
As a consequence, you can't have columns starting with numbers -- I
imagine mysql_fetch_object ensures that the produced object has valid
class attributes names and that's why these columns don't appear
there.

-- 
Alexander Concha
http://www.buayacorp.com


More information about the wp-hackers mailing list