When using mysql_fetch_object()
to return objects from a MySQL query, sometimes column names have spaces in them, and cannot be aliased, such as when running SHOW CREATE PROCEDURE
. The procedure definition is returned in a column named Create Procedure
. In my case, the data abstraction layer only allows the use of mysql_fetch_object()
, so I can't simply use mysql_fetch_assoc()
to work around this problem.
Can I access columns with spaces in when using mysql_fetch_object()
?
To select a column name with spaces, use the back tick symbol with column name. The symbol is ( ` `). Back tick is displayed in the keyboard below the tilde operator ( ~).
The SELECT statement with space in the column's name You can use the square brackets to populate the columns with space in the name.
How do you reference column names with spaces in Python? You can refer to column names that contain spaces or operators by surrounding them in backticks. This way you can also escape names that start with a digit, or those that are a Python keyword.
Column names can contain any valid characters (for example, spaces).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With