catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Add table prefix #94

Closed peter-mw closed 9 years ago

peter-mw commented 10 years ago

Is it possible to add table prefix from the config?

peter-mw commented 10 years ago

hello any info for table prefix support

catfan commented 10 years ago

We have no intention to add this feature. Why not just use constant instead?

peter-mw commented 10 years ago

I need to have multiple db tables by prefix and use them as alias to other tables.

Maybe you can combine it with #97

peter-mw commented 10 years ago

Maybe like that

$database = new medoo(); $database->alias('account', 'my_prefix_account'); // Enjoy $database->insert('account', [ 'user_name' => 'foo' 'email' => 'foo@bar.com', 'age' => 25, 'lang' => ['en', 'fr', 'jp', 'cn'] ]);

TonyLight commented 10 years ago

It would be useful to automatically add a prefix to the tables like that maybe :

$database = new medoo();
$database->prefix('prefix_');
$database->insert('account', [     // => prefix_account
  'user_name' => 'foo'
  'email' => 'foo@bar.com',
  'age' => 25,
  'lang' => ['en', 'fr', 'jp', 'cn']
]);

Can you add this feature ?

catfan commented 10 years ago
$database = new medoo();
// If you want to add this feature here
$database->alias('account', 'my_prefix_account');
// So good for this
$database->insert('account', [
  'user_name' => 'foo'
  'email' => 'foo@bar.com',
  'age' => 25,
  'lang' => ['en', 'fr', 'jp', 'cn']
]);

// But what if I want to fetch date from other table without prefix for special reason?!
$database->select('another_account', 'user_name');
manuvarghese236 commented 10 years ago

prefix is nice feature ,if added

catfan commented 9 years ago

Added this feature finally :)

$database = new medoo([
    'database_type' => 'mysql',
    ...
    'charset' => 'utf8',
    'prefix' => 'PREFIX_'
]);