Fri 03 Oct 2003 04:15:36 PM UTC, comment #3:
another try
cvs -z6 diff -u class.db_pgsql.inc.php
Index: class.db_pgsql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.db_pgsql.inc.php,v
retrieving revision 1.30.2.1.2.4
diff -u -r1.30.2.1.2.4 class.db_pgsql.inc.php
--- class.db_pgsql.inc.php 8 Sep 2003 01:27:44 -0000 1.30.2.1.2.4
+++ class.db_pgsql.inc.php 3 Oct 2003 16:14:10 -0000
@@ -56,7 +56,6 @@
{
$Password = $this->Password;
}
-
if (! $this->Link_ID)
{
$cstr = 'dbname=' . $Database
@@ -66,27 +65,28 @@
. $this->ifadd("'".$Password."'", 'password=');
if ($GLOBALS['phpgw_info']['server']['db_persistent'])
{
- $this->Link_ID=pg_pconnect($cstr);
+ $this->Link_ID=@pg_pconnect($cstr);
}
else
{
- $this->Link_ID=pg_connect($cstr);
+ $this->Link_ID=@pg_connect($cstr);
}
if (! $this->Link_ID)
{
- $this->halt('Link-ID == false, '.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'connect failed');
+ $this->halt(($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'')."connect($Host, $User, \$Password) failed.");
+ return 0;
}
else
{
$this->query("select version()",__LINE__,__FILE__);
$this->next_record();
-
$version = $this->f('version');
$parts = explode(' ',$version);
$this->db_version = $parts[1];
}
}
+ return $this->Link_ID;
}
function to_timestamp($epoch)
@@ -147,6 +147,7 @@
return @pg_close($this->Link_ID);
}
+
function query($Query_String, $line = '', $file = '')
{
if ($Query_String == '')
@@ -154,20 +155,33 @@
return 0;
}
- $this->connect();
-
- /* printf("<br>Debug: query = %s<br>\n", $Query_String); */
+ if (!$this->connect())
+ {
+ return 0; /* we already complained in connect() about that. */
+ };
+ # New query, discard previous result.
+ if ($this->Query_ID)
+ {
+ $this->free();
+ }
+
+ if ($this->Debug)
+ {
+ printf("Debug: query = %s<br>\n", $Query_String);
+ }
$this->Query_ID = @pg_Exec($this->Link_ID, $Query_String);
$this->Row = 0;
- $this->Error = pg_ErrorMessage($this->Link_ID);
+ $this->Error = @pg_ErrorMessage($this->Link_ID);
$this->Errno = ($this->Error == '') ? 0 : 1;
if (! $this->Query_ID)
{
+ return 0;
$this->halt('Invalid SQL: ' . $Query_String, $line, $file);
}
+ # Will return nada if it fails. That's fine.
return $this->Query_ID;
}
@@ -205,8 +219,11 @@
{
$this->Record = @pg_fetch_array($this->Query_ID, $this->Row++);
- $this->Error = pg_ErrorMessage($this->Link_ID);
- $this->Errno = ($this->Error == '') ? 0 : 1;
+ if ($this->Link_ID)
+ {
+ $this->Error = pg_ErrorMessage($this->Link_ID);
+ $this->Errno = ($this->Error == '') ? 0 : 1;
+ }
$stat = is_array($this->Record);
if (!$stat && $this->Auto_Free)
@@ -241,7 +258,7 @@
function transaction_abort()
{
- return pg_Exec($this->Link_ID,'rollback');
+ return @pg_Exec($this->Link_ID,'rollback');
}
function get_last_insert_id($table, $field)
@@ -392,17 +409,19 @@
return pg_numfields($this->Query_ID);
}
+ /* private: error handling */
function halt($msg, $line = '', $file = '')
{
+ $this->Error = @pg_ErrorMessage($this->Link_ID);
+ $this->Errno = 1;
+
if ($this->Halt_On_Error == 'no')
{
return;
}
-
/* Just in case there is a table currently locked */
$this->transaction_abort();
-
if ($this->xmlrpc || $this->soap)
{
$s = sprintf("Database error: %s\n", $msg);
@@ -500,8 +519,13 @@
{
$this->User = $adminname;
$this->Password = $adminpasswd;
+ $this->Database = "template1";
}
+ /*
+ This doesn't work if the httpd server user doesn't have execute permissions on the createdb program
+ */
+ /*
if (! $this->Host)
{
system('createdb ' . $currentDatabase, $outval);
@@ -510,13 +534,16 @@
{
system('createdb -h ' . $this->Host . ' ' . $currentDatabase, $outval);
}
-
if($outval != 0)
{
- /* either the rights r not available or the postmaster is not running .... */
+ // either the rights r not available or the postmaster is not running ....
echo 'database creation failure <BR>';
echo 'please setup the postreSQL database manually<BR>';
}
+ */
+
+ $this->query("CREATE DATABASE $currentDatabase");
+ $this->query("grant all on $currentDatabase.* to $currentUser@localhost identified by
'$currentPassword'");
$this->User = $currentUser;
$this->Password = $currentPassword;
|