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 comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.