Jump to content

Dealing with stupid column names


Recommended Posts

Hi,

 

I am trying to connect to our company software database via PHP. I've got the connection working and can retrieve records etc. However one of my tables has a ridiculous column name that I can't get working.

 

Here's the code...

 

$mssql_server = "sql-primary";
$connectionInfo = array( "Database"=>"FOUR_I_CORE", "UID"=>"...", "PWD"=>"...");

$connnection = sqlsrv_connect( $mssql_server, $connectionInfo);

$sql = "SELECT [REF (SEDOL) No.] FROM [sTO_CORE] WHERE [REF (SEDOL) No.] = $sedol";

$stmt = sqlsrv_query( $connnection, $sql );

				if( $stmt === false) 
					{
    						die( print_r( sqlsrv_errors(), true) );
					}


				while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )

					{
						//echo '<b>Client Ref:</b> ' . $row['REF (SEDOL) No.'] . '<br>';
					}

 

I keep getting the following error message:

 

Array ( [0] => Array ( [0] => 42S22 [sqlSTATE] => 42S22 [1] => 207 [code] => 207 [2] => [Microsoft][sql Server Native Client 10.0][sql Server]Invalid column name 'B7N4L15'. [message] => [Microsoft][sql Server Native Client 10.0][sql Server]Invalid column name 'B7N4L15'. ) )

 

FYI, B7N4L15 is the value being entered as $sedol.

 

I'm pretty sure the problem is with the column name REF (SEDOL) No., but I've no idea how to contain the dodgy name.

 

Unfortunately, I don't have the luxury of renaming the column, so I have to make do. Is there anything I can do to make this work?

 

Cheers

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.