Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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()?

like image 804
Drarok Avatar asked Sep 07 '10 11:09

Drarok


People also ask

How do you select columns with spaces?

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 ( ~).

How do I select a column with spaces in SQL?

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 I select a column name with a space in Python?

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.

Can you have space in column name SQL?

Column names can contain any valid characters (for example, spaces).


1 Answers

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.

like image 155
Pekka Avatar answered Sep 28 '22 07:09

Pekka