Forum Moderators: coopster

Message Too Old, No Replies

Prefixing table names in a query

         

benj0323

11:23 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



First of all, thank you for your help. I would greatly appreciate any help or ideas.

Basically I have a situation where I need to prefix any table name in a query with a string. All of my queries are passed into a class, so I can do whatever I want with the query before actually running the query. At first it seemed like a simple matter because I could simply do this:

eregi_replace("into ", "into $table_prefix", $query);
eregi_replace("from ", "from $table_prefix", $query);
etc.

But then what if we insert into the database and one of the field values contains "into". Also what about select queries that take fields from multiple tables. For example:

select some stuff from tableA hello, tableB hi, tableC anothername

So my question is is there a function that will list out all of the tables being used in a query? Or is there any way to write my own function for that?

Thanks a ton for your help. I really apprecaite it.

jshpro2

11:36 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



If I am understanding you correctly you want to just delete one occurance of the item?


<?
echo (preg_replace("/word/", "", "this is a word, and another word", 1));

// Should output "This is a , and another word"
?>

mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit])

benj0323

4:19 am on Jan 11, 2005 (gmt 0)

10+ Year Member



That might work but what about select queries?

For example:

select sweetness, id, name from sweetness

It would prefix the field name there. Does anyone know of a function to list the tables being accessed in a query or can you think of any way to do this?

Thanks for your help.

benj0323

7:32 am on Jan 12, 2005 (gmt 0)

10+ Year Member



Awesome