php - Run queries to MS SQL server with strange table names -


for application need connect sql server 2008 queries.

i run queries in php on codeigniter framework. access sql database program called "microsoft sql server management studio". tables have strange names dollar signs: trp$lease car example.

the studio data query:

select top 1000 *   [mdatabase].[dbo].[trp$lease car] 

when run query in php installation fails on $ sign:

$data = $this->db->query("select * dbo.trp$lease car"); 

like this:

a php error encountered

severity: notice

message: undefined variable: lease

filename: views/welcome_message.php

line number: 5 database error occurred

error number: 42s02

[microsoft][sql server native client 11.0][sql server]invalid object name 'dbo.trp'.

how need call these tables when running query php?

edit

the problem appears on tables space in name... query trp$invoice works. in case trp$lease car problem think..

this due fact have query in double-quotes. when php encounters double-quoted string containing $something, treat $something variable , attempt substitute value. in case, have tpr$lease in string - php attempts resolve variable $lease - haven't defined - , gives warning message indicated. there 2 ways of dealing it.

  1. escape dollar sign: "select * tpr\$lease" - telling php need dollar sign there.

  2. use single-quoted string: 'select * tpr$lease' - php not variable substitution in single-quoted strings.

obviously, adjust actual sql statements according specific schema.

edit: if table name contains spaces, have use square brackets [ ... ] around tabla name:

"select * [tpr\$lease car]" 

note ms sql specific syntax. not work on other database engines, (to knowledge) ms allows spaces in table names.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -