How do you access columns with a space in them via mysql_fetch_object? How do you access columns with a space in them via mysql_fetch_object? php php

How do you access columns with a space in them via mysql_fetch_object?


Generally speaking,

$recordname->{"my column name"} 

will do the trick.

You can also do a print_r($record); to find out how the columns are represented in the object.


This took me a while to crack, so I thought I'd post it here, hence the quick answer. :)

// Internally, this db abstraction layer uses mysql_fetch_object().$query = $db->query('SHOW CREATE PROCEDURE `%s`', 'test');foreach ($query as $row) {    $procedure = $row->{'Create Procedure'};}

I don't know if this is specific to a PHP version, but it works under PHP 5.3.1 on Windows, at least.


Use quotes. Example: "name with spaces"