darkain / pudl

PHP Universal Database Library - connects to and generates queries for SQL Servers
BSD 2-Clause "Simplified" License
28 stars 5 forks source link

Prefix #4

Closed NightScript370 closed 5 years ago

NightScript370 commented 6 years ago

It would be cool if you could set your own prefix once in the config so that way you don't have to manually put in a prefix every time you type $db->insert

darkain commented 6 years ago

This is already supported.

$db = pudl::instance([
    'type'     => 'MySqli',
    'server'   => 'localhost',
    'database' => 'DatabaseName',
    'username' => 'AwesomeGuy9001',
    'password' => 'SuperDuperSecretSauce',
    'prefix' => 'tableprefix_',
]);

Once this is done, PUDL will auto-translate any table with the prefix "pudl_" to the corresponding prefix. So all you'd have to do is:

$db->insert('pudl_mydbtable' ['column'=>'value']);
//INSERT INTO `tableprefix_mydbtable` (`column`) VALUES ('value')

(note: this was typed by hand, so may contain typos)

darkain commented 6 years ago

I'm currently in the process of expanding table prefixing quite a bit beyond what is listed above. Multiple prefixes per config, and an unnamed prefix will both be supported (I'll have examples in a unit test file along with these changes hopefully later today)

darkain commented 6 years ago

I've updated 'prefix' handling and added a collection of examples within the unit tests.

https://github.com/darkain/pudl/blob/master/test/prefix.inc.php

NightScript370 commented 6 years ago

Can you make it so I don't need to type pudl_ in the front?

darkain commented 5 years ago

@NightYoshi370 the latest HEAD repository no longer requires it. Check the examples in the prefix unit tests I linked in the previous comment.

NightScript370 commented 5 years ago

ok. Issue resolved, so I'll close this