0

I have a ticket system I set up for multiple websites. Each website has its own database and the tables in each database are the same on all website with a few minor changes on each site.

I'm creating a CMS to manage all the sites from one website.

I can query my databases and have variable setup like this to call each database.

  • $database_1 = 'cats';
  • $database_2 = 'dogs';

Then call the database like this in a query:

SELECT `whatever` FROM {$database_1}.`support_ticket`..etc

My question is how can I insert data into the database tables?

This works for me:

$addticket = DB::getInstance()->insert('cats.`st_messages`', array( etc..

But I want it to work like this:

$addticket = DB::getInstance()->insert('{$database_1}.`st_messages`', array( etc..

Not sure why that won't work..?

So to reiterate:

  • $database_1 = 'cats';
  • This works: 'cats.st_messages'
  • This is not working, but want it to: '{$database_1}.st_messages'

If someone could explain what I'm doing wrong by using the variable in the insert query I would appreciate it.

2
  • 1
    Connect to each database separately and then refer to that connection ID when running your query Commented Oct 6, 2014 at 2:06
  • @JohnConde I believe that's what I'm trying to do. I have a DB called cats and on called dogs etc.. Each is connected separately. I refer to the connection by $database_1 = 'cats'; ,but when running my insert line '{$database_1}.st_messages' it's not reading it as 'cats.st_messages'......What I'm asking is what is wrong with this: '{$database_1}.st_messages' ..? Commented Oct 6, 2014 at 2:34

1 Answer 1

1

You must use double quotes when building your strings otherwise they will not be interpolated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.