Re: [Phplib-users] DB_Sql question
by Andrew Crawford other posts by this author
Nov 8 2005 5:11PM messages near this date
[Phplib-users] DB_Sql question
|
[Phplib-users] sourceforge project page down & real $sess->url() stuff
Howdy,
I haven't spent a lot of time dissecting the code in DB_Sql but, my
understanding is that DB_Sql's connect() is an *internal* instance
method, not intended for use like that. I would probably do the same
thing by declaring a separate DB_Sql extension class for each database.
That would be something like this:
class DB_Example extends DB_Sql {
var $classname = "db_example";
var $Host = "localhost";
var $Database = "DB1";
var $User = "example";
var $Password = "password";
var $Auto_Free = "true";
var $Halt_On_Error = "report";
}
class DB_Example2 extends DB_Sql {
var $classname = "db_example2";
var $Host = "localhost";
var $Database = "DB2";
var $User = "example2";
var $Password = "password2";
var $Auto_Free = "true";
var $Halt_On_Error = "report";
}
Then, you could do basically the same thing this way:
$exampledb = new DB_Example;
$query = "SELECT name,id FROM FILE WHERE datatype='folder'";
$exampledb-> query($query);
while($exampledb-> next_record()) {
echo $exampledb-> f(0) . "[" . $exampledb->f(1) . "]<br />\n";
}
$exampledb2 = new DB_Example2;
$query2 = "SELECT name,id FROM FILE WHERE datatype='folder'";
$exampledb2-> query($query2);
while($exampledb2-> next_record()) {
echo $exampledb-> f(0) . "[" . $exampledb->f(1) . "]<br />\n";
}
$exampledb-> query($query);
while($exampledb-> next_record()) {
echo $exampledb-> f(0) . "[" . $exampledb->f(1) . "]<br />\n";
}
This definitely works.
Andrew Crawford
Kelby Zorgdrager wrote:
> Folks:
>
> Gotta question for you. I am experiencing a unexpected problem when
> using the DB_Sql class. It appears that if I create a DB_Sql object to
> one database (and perform a query) then create a second DB_Sql object
> to another database (and perform a query), when I return to the first
> object, it's connection state is invalid. Due to the architecture of
> our app, I can not consolidate the two objects into one (that would be
> reused).
>
> I have attached a sample as an example to show the problem.
>
> Assume for the example there are:
> --> two databases, DB1 and DB2
> --> a table in each db (DB1.FILE and DB2.USER)
>
> I have attached two SQL files for the tables along with the example.
> Any insight into why I am seeing this would be greatly appreciated.
>
> Thanks.
>
> KZ
>
>
> ------------------------------------------------------------------------
>
> <?php
> include_once ("db_mysql.inc");
>
> $dbConnection = new DB_Sql;
> $dbConnection->Database = $dbName;
> if (!$dbConnection->connect("DB1")) {
> $error = "Failed to connect to $dbName";
> echo "Failed to initialize: $error<br>";
> exit;
> }
>
> $dbConnection->query("SELECT name,id FROM FILE WHERE datatype='folder'");
> while($dbConnection->next_record()) {
> echo "<BR>".$dbConnection->f(0)."[".$dbConnection->f(1)."]";
> }
>
> $dbConnection2 = new DB_Sql;
> $dbConnection2->connect("DB2");
> $dbConnection->query("SELECT name,id FROM USER");
> while($dbConnection->next_record()) {
> echo "<BR>".$dbConnection->f(0)."[".$dbConnection->f(1)."]";
> }
>
> /*
> * when this is queried, it returns nothing.. even though it should
> * return the same 'set' as the first time it was queried above.
> */
> $dbConnection->query("SELECT name,id FROM FILE WHERE datatype='folder'");
> while($dbConnection->next_record()) {
> echo "<BR>".$dbConnection->f(0)."[".$dbConnection->f(1)."]";
> }
> ?>
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Phplib-users mailing list
Phplib-users@[...].net
https://lists.sourceforge.net/lists/listinfo/phplib-users
Thread:
Kelby Zorgdrager
Andrew Crawford
|