Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-07-09 03:51:10

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Mod: Generic DB (gDB) Class

I created a class that wraps the txp db functions found in ./lib/txplib_db.php so that multiple database connections can be open at the same time. This is particularly useful when connecting to non txp databases for integration plugins.

Download txplib_gdb.php

Example usage:
==
<pre>
<code>
include(“./lib/mem_lib_gdb.php”);

// open a connection to database textpattern_db on localhost using a table prefix of “txp_”
$db1 =& new gDB(‘localhost’,‘textpattern_db’,‘user1’,‘pass1’,‘txp_’);

// get all links
$rs = $db1->safe_rows(‘*’, ‘txp_link’, ‘1’);

// open a connection to database events on localhost with no table prefix
$db2 =& new gDB(‘localhost’,‘events’,‘user2’,‘pass2’);

$field = $db2->safe_field(‘value’,‘some_table’,’ id=5’);

$field = $db1->safe_field(…);
</code>
</pre>
==

Edit: Removed all of the select_db() calls from the example code because it is not needed—the db functions of txplib_db.php pass the resource link of the connection.

Last edited by Manfre (2004-07-09 04:03:32)

Offline

#2 2005-03-17 07:07:55

King Rat
Member
Registered: 2004-11-11
Posts: 20

Re: Mod: Generic DB (gDB) Class

Well, I was about to write this library, since I’ve been working on a plugin that accessed a non-txp database and was having problems.

However, I rewrote it to use this lib, and — I’m still having problems.

Essentially, if I my plugin’s tag is the last one on the page, everything is fine. If I follow it by something like <code><txp:article_custom /></code> then I get this:

<code>Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /path/to/textpattern/lib/txplib_db.php on line 106</code>

and no output from the txp tag after my plugin tag. This is the same behavior I was observing without the gdb lib. So I’m guessing there’s something else going on here.

Any ideas?

Offline

#3 2005-03-18 01:37:45

King Rat
Member
Registered: 2004-11-11
Posts: 20

Re: Mod: Generic DB (gDB) Class

Okay, I think I got this figured out. I had to use <code>mysql_select_db($DB->db);</code> at the end of my plugin to get php to query the proper database

…and they say learning is fun ;P

Offline

Board footer

Powered by FluxBB