Welcome Guest, Not a member yet? Register   Sign In
SQL table name with spaces
#1

Hello,

I have to connect to another database to retrieve data from there.
In this database, table names contain spaces, hyphens and other extra characters (ex. $).

Used DB driver SQLSRV.

See it query:
$db->table('Company Central-Europe Kft$SMS_NAV_IF')->select('Status')->getCompiledSelect();

Result:
SELECT "Status" FROM "Company_Live"."dbo"."Company" Central-Europe" "Kft$SMS_NAV_IF"

This query will of course return an error.
Because of this: "Company" Central-Europe" "Kft$SMS_NAV_IF"
The query builder splits the table name.

My question is, is there a nice solution to make this work?
Reply
#2

(This post was last modified: 06-06-2022, 01:08 PM by iRedds.)

Raw query. That is, without using QueryBuilder.

If possible, create an issue.

2maintainers: "The fried rooster pecked".
Reply
#3

@kovijanny , Is it possible to replace space in the name of the table with an underscore?

Whoever named the table used a very bad practice. You should never use spaces while naming database items.
Reply
#4

(06-06-2022, 01:24 AM)kovijanny Wrote: In this database, table names contain spaces, hyphens and other extra characters (ex. $).

Some people just like to look for trouble! I think iRedds is right, just use raw queries since you have a weird setup.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB