Adding an alternative database driver > Invisionize.eu - IP.Board (IPB) News
Kanał Rss Kanał Rss
Kanał Atom Kanał Atom

Adding an alternative database driver

wersja drukowalna wersja Microsoft Word wersja HTML

This is a trick you can use in your IP.Board code, and it also can come in handy for IP.Content as well; it was working with a client on their IP.Content page that I found this code.

The IP.Board database object (usually the $this->DB object in the IP.Board code) is set up by default to connect to the database that has its info defined in your conf_global.php file. You can use the IP.Board framework to quickly create a secondary database connection that has access to all of the same functions. This comes in very handy if you ever need to connect to a database external to your IP.Board install to pull in info from it.

Here's the basic code for it:

/* Set up our alternate database object */
ips_DBRegistry::setDB( 'mysql', 'db2', array( 'sql_database' => '***', 'sql_user' => '***', 'sql_pass' => '***', 'sql_host' => '***', 'sql_charset' => '***', 'sql_tbl_prefix' => '***' ) );
$DB2 = $this->registry->DB( 'db2' );

Just fill in that info related to the database on the top line, and $DB2 now is a database object that connects to this secondary database.

If your code is inside a class, you can also adapt this code to create a $this->DB2 object, it's best to do that in the class's constructor. That way, the database object exists throughout the class.

śro, 24 listopad 2010

Komentarze:

Brak komentarzy

Imię/Nick:

Adres email:

Strona WWW:

Treść Komentarza: