php-sql-query-builder
php-sql-query-builder copied to clipboard
Database + table name
I was expecting to be able to build a query along the lines of:
$queryBuilder->select()->setTable('users.user');
Where the table user
exists within a database users
.
Am I missing an undocumented method that lets me set the DB another way, or do I have to apply a USE
SQL command ahead of running the query?
The library appears to support this through the Table::__construct(.., $schema)
parameter and Table::setSchema()
, which are also consumed correctly by the Writer implementation.
The only problem is, it seems that the query builder class does not expose this functionality. The $builder->select()->setTable()
method only allows a string, or an array with name/alias. It does not allow a schema, nor does it allow a custom Table object to be passed in.
@nilportugues Do I understand correctly? If so, what approach would you prefer for solving this? I would be interested in writing a patch for to fix this.
@andybee we use query builder in association with PDO, hence we sconnect and select the database through PDO, before using query builder. You can try that as well, hope this answer is not too late?
@marcus-hiles The issue I was experiencing is that in our multi-tenant environment (where we use databases to separate concerns), the same script may need to use multiple different databases and re-establishing the connection to the server just to switch DB would be inefficient.
Oh ok, gotcha @andybee Then I think your best bet here is to mysqli. Back to the basics man :-)