[pLog-svn] r2186 - plog/trunk/class/database/pdb/drivers
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Jun 9 14:09:10 GMT 2005
Author: oscar
Date: 2005-06-09 14:09:09 +0000 (Thu, 09 Jun 2005)
New Revision: 2186
Modified:
plog/trunk/class/database/pdb/drivers/pdbdriverbase.class.php
plog/trunk/class/database/pdb/drivers/pdbmysqldriver.class.php
Log:
a couple of improvements and a fix for a strange situation with two connections
to different databases but in the same host and using the same connection
parameters...
Modified: plog/trunk/class/database/pdb/drivers/pdbdriverbase.class.php
===================================================================
--- plog/trunk/class/database/pdb/drivers/pdbdriverbase.class.php 2005-06-09 13:34:52 UTC (rev 2185)
+++ plog/trunk/class/database/pdb/drivers/pdbdriverbase.class.php 2005-06-09 14:09:09 UTC (rev 2186)
@@ -4,13 +4,16 @@
class PDbDriverBase extends Object
{
-
- var $_debug;
+
+ var $_dbname;
+ var $_host;
+ var $_user;
+ var $_password;
function PDbDriverBase()
{
- $this->Object();
-
+ $this->Object();
+
$this->_debug = false;
}
@@ -32,17 +35,27 @@
function Connect( $host, $username, $password, $dbname )
{
- // to be implemented by child classes
+ $this->_host = $host;
+ $this->_username = $username;
+ $this->_password = $password;
+ $this->_dbname = $dbname;
+
+ // extra functionality to be implemented by child classes...
}
function PConnect( $host, $username, $password, $dbname )
{
- // to be implemented by child classes
- }
-
- function Close()
- {
- // to be implemented by child classes
+ $this->_host = $host;
+ $this->_username = $username;
+ $this->_password = $password;
+ $this->_dbname = $dbname;
+
+ // extra functionality to be implemented by child classes...
+ }
+
+ function Close()
+ {
+ // to be implemented by child classes
}
function ErrorMsg()
@@ -53,28 +66,28 @@
function Insert_ID()
{
// to be implemented by child classes
- }
+ }
function Affected_Rows()
{
// to be implemented by child classes
- }
-
- /**
- * @private
- */
- function _debugQuery( $query )
- {
- if( $this->_debug ) {
- print("<hr/>$query<hr/>");
- }
-
- return( true );
- }
-
- function setDebug( $debug )
- {
- $this->_debug = $debug;
+ }
+
+ /**
+ * @private
+ */
+ function _debugQuery( $query )
+ {
+ if( $this->_debug ) {
+ print("<hr/>$query<hr/>");
+ }
+
+ return( true );
+ }
+
+ function setDebug( $debug )
+ {
+ $this->_debug = $debug;
}
}
?>
\ No newline at end of file
Modified: plog/trunk/class/database/pdb/drivers/pdbmysqldriver.class.php
===================================================================
--- plog/trunk/class/database/pdb/drivers/pdbmysqldriver.class.php 2005-06-09 13:34:52 UTC (rev 2185)
+++ plog/trunk/class/database/pdb/drivers/pdbmysqldriver.class.php 2005-06-09 14:09:09 UTC (rev 2186)
@@ -7,22 +7,31 @@
{
var $_res;
+ var $_dbname;
function PDbMySQLDriver()
{
- $this->PDbDriverBase();
+ $this->PDbDriverBase();
}
function Execute( $query )
{
- // execute the query and see whether it was incorrect
+ // execute the query and see whether it was incorrect
$this->_debugQuery( $query );
+
+ // as per the comments in http://www.php.net/manual/en/function.mysql-select-db.php, looks like
+ // in situations where we've got more than one table in the same server using the same
+ // connection parameters, we either need to select the database *everytime* we want to make
+ // a query or use slightly different connection paramters. I am not sure if this has any
+ // performance hit, though.
+ mysql_select_db( $this->_dbname, $this->_res );
+
$result = mysql_query( $query, $this->_res );
- if( !$result ) {
- if( $this->_debug ) {
- print("<hr/>ERROR: $query<hr/>");
+ if( !$result ) {
+ if( $this->_debug ) {
+ print("<hr/>ERROR MESSAGE: ".$this->ErrorMsg()."<br/>");
}
- return false;
+ return false;
}
// if not, create a RecordSet based on it
@@ -32,6 +41,8 @@
function Connect( $host, $username, $password, $dbname )
{
+ PDbDriverBase::Connect( $host, $username, $password, $dbname );
+
// try to connect and quit if unsuccessful
$this->_res = mysql_connect( $host, $username, $password );
if( !$this->_res )
@@ -43,20 +54,22 @@
function PConnect( $host, $username, $password, $dbname )
{
+ PDbDriverBase::Connect( $host, $username, $password, $dbname );
+
// try to connect and quit if unsuccessful
$this->_res = mysql_pconnect( $host, $username, $password );
if( !$this->_res )
- return false;
+ return false;
// continue otherwise and try to select our db
return( mysql_select_db( $dbname, $this->_res ));
- }
-
- function Close()
- {
- return( mysql_close( $this->_res ));
}
+ function Close()
+ {
+ return( mysql_close( $this->_res ));
+ }
+
function ErrorMsg()
{
return( mysql_error( $this->_res ));
@@ -65,11 +78,11 @@
function Insert_ID()
{
return( mysql_insert_id( $this->_res ));
- }
-
- function Affected_Rows()
- {
- return( mysql_affected_rows( $this->_res ));
- }
+ }
+
+ function Affected_Rows()
+ {
+ return( mysql_affected_rows( $this->_res ));
+ }
}
?>
\ No newline at end of file
More information about the pLog-svn
mailing list