Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Unable to connect to default database
I am not able to connect default database.
For example, I have database A and B.
Database A is default database and the
B.user have similar schema.
I connect to A.user.
I connect to B.user.
Connecting back to A.user.
Then, somehow what I get is B.user data.
Do you know why this is happening?
Possibly, program is holding the database B instance or something.
So, I tried following but it dose not work at all.
Here is my part of source code from numbering 3.
// Sets original properties
$user = Model_User::find_by_username('aaaBBBBB');
The error message says "Column not found" because of referencing wrong database.
I set to default database but it try to connect to wrong database.
I also check following and it says "default".
It seems it connects to right database but using wrong $_properties.
Do you know how to reset the orm $_properties?
I tried unset(static::$_properties['some_attribute']), but not working at all.
An ORM model is record representation, so is it always linked to a single table of a single database.
It will probably be possible, with quite a bit of effort, to cleanly swap databases, but it will never work if the table's schema in the database isn't completely identical.
But, it is possible to change $_properties.
Why is that?
Or, it is not intended to change？
From within the class, everything can be changed. That doesn't mean you should.
Everything that is defined as "static" is global, for all instances of the class. So changing it will have an impact on all instances, also the onces already created with the old property list.
Yes, that is what I expect.
Well...I might have to find another way.
You could by explicitly closing the database connection before you change databases and try to access the new database:
Then set a new connection on the model, make your changes, and try again.
I assume that because the connection is active, it will keep using that connection. The database layer does not do an explicit "USE" when you connect, so if both database are served by the same database engine, changes are the same connection is re-used.
Thank you for that.
I will try that.
I solved myself.
To refresh the $_properties, I did following.
static::$_properties_cached = array();
static::$_properties = array( 'id','username','nickname','email');
Do you think this is okay?
You shouldn't do that, that erases the entire ORM properties cache.
$class = get_class();
static::$_properties_cached[$class] = array();
to only erase the cache of the current model class.
I did that.
But, it gives me following error.
Fuel\Core\FuelException [ Error ]:
No properties found in model.
Sorry, my bad, the code uses array_key_exists.
So it should be
Thank you for your help.
Now it is working.
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion