aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul S. Owen <psotfx@users.sourceforge.net>2001-02-26 01:00:57 +0000
committerPaul S. Owen <psotfx@users.sourceforge.net>2001-02-26 01:00:57 +0000
commitcb964c96c74c0b8bd47ff01f2e45616d8c2413b8 (patch)
tree6a21f69e150f68bf71c778819974b07d461482c2
parent83b6163b4b75b7d06178dbf43719dbb1be1392d1 (diff)
downloadforums-cb964c96c74c0b8bd47ff01f2e45616d8c2413b8.tar
forums-cb964c96c74c0b8bd47ff01f2e45616d8c2413b8.tar.gz
forums-cb964c96c74c0b8bd47ff01f2e45616d8c2413b8.tar.bz2
forums-cb964c96c74c0b8bd47ff01f2e45616d8c2413b8.tar.xz
forums-cb964c96c74c0b8bd47ff01f2e45616d8c2413b8.zip
A few corrections inc. DB2 compatibility
git-svn-id: file:///svn/phpbb/trunk@66 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r--phpBB/db/odbc.php87
1 files changed, 64 insertions, 23 deletions
diff --git a/phpBB/db/odbc.php b/phpBB/db/odbc.php
index e0794b1454..f55fa178e7 100644
--- a/phpBB/db/odbc.php
+++ b/phpBB/db/odbc.php
@@ -41,25 +41,36 @@ class sql_db
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
- $this->persistency = $persistency;
- $this->user = $sqluser;
- $this->password = $sqlpassword;
- $this->server = $sqlserver;
- $this->dbname = $database;
-
- if($this->user || $this->password)
- {
-// $this->server = "DSN=".$this->server;
- }
- if($this->user)
+ if(eregi("^([[:alnum:]]+):([[:alnum:]]+)$", $sqlserver, $db_type))
{
- $this->dsn .= ";UID=".$this->user;
+ $this->persistency = $persistency;
+ $this->user = $sqluser;
+ $this->password = $sqlpassword;
+ $this->dbname = $database;
+
+ $this->server = $db_type[2];
+ $db_type = strtoupper($db_type[1]);
+
+ switch($db_type)
+ {
+ case 'MSACCESS':
+ $this->db_type = "msaccess";
+ break;
+ case 'MSSQL':
+ $this->db_type = "mssql";
+ break;
+ case 'DB2':
+ $this->db_type = "db2";
+ break;
+ default:
+ $this->db_type = "";
+ }
}
- if($this->password)
+ else
{
- $this->dsn .= ";PWD=".$this->password;
+ return false;
}
-
+
if($this->persistency)
{
$this->db_connect_id = odbc_pconnect($this->server, "", "");
@@ -71,6 +82,10 @@ class sql_db
if($this->db_connect_id)
{
+ if($this->db_type == "db2")
+ {
+ @odbc_autocommit($this->db_connect_id, off);
+ }
return $this->db_connect_id;
}
else
@@ -133,7 +148,12 @@ class sql_db
$num_rows = $limits[2];
}
- $this->query_result = @odbc_exec($this->db_connect_id, $query);
+ if($this->db_type == "db2")
+ {
+ $query .= " FETCH FIRST ".($row_offset+$num_rows)." ROWS ONLY OPTIMIZE FOR ".($row_offset+$num_rows)." ROWS";
+ }
+
+ $this->query_result = odbc_exec($this->db_connect_id, $query);
$query_limit_offset = $row_offset;
$this->result_numrows[$this->query_result] = $num_rows;
@@ -157,11 +177,12 @@ class sql_db
$i = $row_offset + 1;
$k = 0;
- while(odbc_fetch_row($result_id, $i) && $k < $this->result_numrows[$result_id])
+ while(@odbc_fetch_row($result_id, $i) && $k < $this->result_numrows[$result_id])
{
+
for($j = 1; $j < count($this->result_field_names[$result_id])+1; $j++)
{
- $this->result_rowset[$result_id][$k][$this->result_field_names[$result_id][$j-1]] = odbc_result($result_id, $j);
+ $this->result_rowset[$result_id][$k][$this->result_field_names[$result_id][$j-1]] = @odbc_result($result_id, $j);
}
$i++;
$k++;
@@ -173,18 +194,38 @@ class sql_db
}
else
{
- $this->query_result = odbc_exec($this->db_connect_id, $query);
+ $this->query_result = @odbc_exec($this->db_connect_id, $query);
if($this->query_result)
{
- // This works for MSSQL, MS Access ... no idea about other DBs ...
- $id_result = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY AS last_id");
+ switch($this->db_type)
+ {
+ case 'msaccess':
+ $sql_id = "SELECT @@IDENTITY";
+ break;
+ case 'mssql':
+ $sql_id = "SELECT @@IDENTITY";
+ break;
+ case 'db2':
+ $sql_id = "VALUES(IDENTITY_VAL_LOCAL())";
+ break;
+ default:
+ $sql_id = "";
+ }
+ $id_result = @odbc_exec($this->db_connect_id, $sql_id);
if($id_result)
{
- @odbc_fetch_row($id_result);
- $this->next_id[$this->query_result] = odbc_result($id_result, 1);
+ $row_result = @odbc_fetch_row($id_result);
+ if($row_result)
+ {
+ $this->next_id[$this->query_result] = odbc_result($id_result, 1);
+ }
}
}
+ if($this->db_type == "db2")
+ {
+ odbc_commit($this->db_connect_id);
+ }
$this->query_limit_offset[$this->query_result] = 0;
$this->result_numrows[$this->query_result] = 0;