PHP Aura SQL, swithing database inside class -
I'm a little confused here, I'm struggling with ease and a bit more in OP. I am using Aura SQL (PHP) and I have achieved a lot, however, I have become necessary to connect with more than one DB to update some legacy code.
class core {public $ pdo; Private stable $ example; Personal Function __Composition () {$ this- & gt; Pdo = New extended pado ('mysql: host = localhost; charset = utf8; dbname = db', 'user', 'pass'); $ This- & gt; Pedo-> Set Attribution (PDO :: MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8'); } Public stable work getInstance () {if (! Isset (self: $ example)) {$ object = __CLASS__; Auto :: $ example = new $ object; } Return Self: $ example; }}
I have tried to modify values by passing values through the constructor, but, it is being ignored eg:
private Function __construct $ Db_name) {if! Below ($ db_name)) {$ this-> Db = $ db_name; } And {$ this- & gt; Db = 'default_db'; } $ This- & gt; Pdo = new extended pado ('mysql: host = localhost; charset = utf8; dbname ='. $ This- & gt; db. '', ....
Generally You will use getInstance (), but I am trying to use a new object immediately to access other databases.
Thanks for any advice.
Please checkout through which you can create a default connection, and take the code snippet from the rest of the connection.
< Pre> & lt ;; Php use Aura \ Sql \ connection locator; Aura \ Sql \ ExtendedPdo; // Use the default connection $ default = function () {New Extended Pado Back ('mysql: host = default.db.localhost; dbname = databases ',' Username ',' password ');}; // read connection $ read = array (' slave1 '=> function ()) returned new extended pado (' mysql: host = slave1.db.localhost ; Dbname = database ',' username ',' password ');},' slave2 '= & gt; function () {new extended pado back (' mysql: host = slave2.db.localhost; Dbname = database ',' username ',' password '); }, 'Slave 3' = & gt; Function () {New extended pado back ('mysql: host = slave 3.db.localhost; dbname = database', 'username', 'password'); },); // write to write $ connection = array ('master' => function () {return new extended pado ('mysql: host = master.db.localhost; dbname = database', 'username', 'password ');},); // Configure Locator $ Connection = New Connection at Construction Timeline ($ $ Default, $ write, write $); $ Default_connection = $ Connection- & gt; GetDefault (); $ Read_slave1_connection = $ connections- & gt; GetRead ('slave1'); $ Read_any_connection = $ connections-> GetRead (); Write $ _connection = $ connection-> Sociable ();
Comments
Post a Comment