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

David Gard dgard at dynedrewett.com
Thu Apr 5 08:35:06 UTC 2012

First off, for the query, try this code. WP will prepare it correctly for a MySQL query then -

$query = "SELECT * FROM "{DBNAME}" WHERE id = '{$target}'";
print_r( $wpdb->get_row( $wpdb->prepare( $query, ARRAY_A ) ) );

As for the missing columns - a quick search shows that the problem is common, with the solution seeming to be 'change column names to not start with numbers'. Not ideal, but maybe the only option.

Any way, my be worth outputting any errors after the query above to see if you can get some more information from $wpdb -

echo '<pre>$wpdb->last_query: '; print_r($wpdb->last_query); echo '</pre>';
echo '<pre>$wpdb->last_error: '; print_r($wpdb->last_error); echo '</pre>';

If you don't get any information then you know for sure that it is not a query error, so explore the MySQL bug route. If you do get an error, then hopefully it will lead you to an answer.

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Alexander Höreth
Sent: 04 April 2012 21:22
To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] $wpdb: columns with digit names

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!?
wp-hackers mailing list
wp-hackers at lists.automattic.com

P  Please consider the environment - do you really need to print this email?

This email and any files transmitted with it are confidential, intended solely for the individual(s) or entity to whom they are addressed and may be privileged. If you have received this email in error please immediately notify the sender by return email or alternative means and then delete this email. If you are not the intended recipient(s), you accept that any form of distribution, copying or use of this communication or the information contained within it is strictly prohibited and may be unlawful. 
Although this email message has been virus checked, you accept that internet communications cannot be guaranteed to be secure or free of viruses and shall not seek to hold us liable in the event of any loss suffered.

The contents of this email, including any files transmitted with it, are sent on behalf of Dyne Drewett Solicitors Limited and not by the individual sender. Any opinion contained in this email or other information or files transmitted with it that do not relate to our business is personal to the sender and shall not be deemed to be endorsed by us. 
Dyne Drewett Solicitors Limited, a Limited Company
Registered in England &Wales: number 07552781
Registered Office: 11 Cheap Street, Sherborne, Dorset DT9 3PU. 
We use the word 'Partner' to refer to a director of the Limited Company as this is more readily understood terminology amongst clients and senior professionals. A list of directors is available for inspection at each of our offices. 
Authorised and regulated by the Solicitors Regulation Authority (SRA) ID Number: 558227, and a member of LawNet. 

Details of the SRA Code of Conduct can be found on their website. 

Please visit our website www.dynedrewett.com for further details about our staff and services.

More information about the wp-hackers mailing list