Closed codecowboy closed 9 years ago
See the documentation on multiple connections for examples. All of the queries accept an optional trailing parameter that specifies the connection using a string key.
You should only have to use ORM::configure()
once.
"You should only have to use ORM::configure() once." That's what I thought but it was not true in my use case. I am developing a WordPress plugin which needs access to a legacy database.
If I called ORM::Configure in plugin code, it was not available in templates. e.g.:
$job = ORM::for_table('jobs_ol')->where('job_ref', (int) $wp_query->get('job'))->find_one();
resulted in:
Uncaught exception 'PDOException' with message 'could not find driver'
However, ensuring that ORM::Configure() was called earlier in the plugin execution chain resolved this for me. In case others are using idiorm and WordPress Plugin Boilerplate, this meant ensuring it was called by the main plugin file's constructor.
I don't know much of WordPress plugin development, but it seems to me there shouldn't be any queries from templates anyway unless I am misunderstanding terminology here. Either way I am glad you got it sorted out. On 4 May 2015 15:42, "Luke Mackenzie" notifications@github.com wrote:
Closed #271 https://github.com/j4mie/idiorm/issues/271.
— Reply to this email directly or view it on GitHub https://github.com/j4mie/idiorm/issues/271#event-296311016.
If I want to reuse a configured connection, what pattern would you recommend for using it throughout a small application? Use a singleton? The objective is to not have to repeat calls to
ORM::configure()
I may also need multiple connections so maybe a factory would be better. Are there any examples of this anywhere?