mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-24 20:01:36 +02:00
formatting
This commit is contained in:
parent
c016448915
commit
4d929cadc2
@ -15,133 +15,155 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
class db {
|
class db
|
||||||
var $Host = "";
|
{
|
||||||
var $Database = "";
|
var $Host = '';
|
||||||
|
var $Database = '';
|
||||||
|
|
||||||
var $Link_ID = 0;
|
var $Link_ID = 0;
|
||||||
var $Query_ID = 0;
|
var $Query_ID = 0;
|
||||||
var $Record = array();
|
var $Record = array();
|
||||||
var $Row;
|
var $Row;
|
||||||
|
|
||||||
var $Error = "";
|
var $Error = '';
|
||||||
|
|
||||||
var $Auto_Free = 0; ## Set this to 1 for automatic msql_free_result()
|
|
||||||
|
|
||||||
function connect() {
|
var $Auto_Free = 0; ## Set this to 1 for automatic msql_free_result()
|
||||||
// Not connected? Then connect?
|
|
||||||
if ( 0 == $this->Link_ID ) {
|
|
||||||
// Check for local connect
|
|
||||||
$this->Link_ID = empty($this->Host)?
|
|
||||||
$this->Link_ID=msql_pconnect():
|
|
||||||
$this->Link_ID=msql_pconnect($this->Host);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Still not connected? Raise error.
|
|
||||||
if ( 0 == $this->Link_ID ) {
|
|
||||||
$this->halt("Link-ID == false, pconnect failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select current database
|
function connect()
|
||||||
if (!msql_select_db($this->Database, $this->Link_ID)) {
|
{
|
||||||
$this->halt("cannot use database ".$this->Database);
|
// Not connected? Then connect?
|
||||||
}
|
if ( 0 == $this->Link_ID )
|
||||||
}
|
{
|
||||||
|
// Check for local connect
|
||||||
function query($Query_String) {
|
$this->Link_ID = empty($this->Host)?
|
||||||
$this->connect();
|
$this->Link_ID=msql_pconnect():
|
||||||
|
$this->Link_ID=msql_pconnect($this->Host);
|
||||||
|
}
|
||||||
|
|
||||||
# printf("Debug: query = %s<br>\n", $Query_String);
|
// Still not connected? Raise error.
|
||||||
|
if ( 0 == $this->Link_ID )
|
||||||
|
{
|
||||||
|
$this->halt('Link-ID == false, pconnect failed');
|
||||||
|
}
|
||||||
|
|
||||||
$this->Query_ID = msql_query($Query_String,$this->Link_ID);
|
// Select current database
|
||||||
$this->Row = 0;
|
if (!msql_select_db($this->Database, $this->Link_ID))
|
||||||
$this->Error = msql_error();
|
{
|
||||||
if (!$this->Query_ID) {
|
$this->halt('cannot use database '.$this->Database);
|
||||||
$this->halt("Invalid SQL: ".$Query_String);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->Query_ID;
|
function query($Query_String)
|
||||||
}
|
{
|
||||||
|
$this->connect();
|
||||||
|
|
||||||
function next_record() {
|
# printf("Debug: query = %s<br>\n", $Query_String);
|
||||||
$this->Record = msql_fetch_array($this->Query_ID);
|
|
||||||
$this->Row += 1;
|
|
||||||
$this->Error = msql_error();
|
|
||||||
|
|
||||||
$stat = is_array($this->Record);
|
$this->Query_ID = msql_query($Query_String,$this->Link_ID);
|
||||||
if (!$stat && $this->Auto_Free) {
|
$this->Row = 0;
|
||||||
msql_free_result($this->Query_ID);
|
$this->Error = msql_error();
|
||||||
$this->Query_ID = 0;
|
if (!$this->Query_ID)
|
||||||
}
|
{
|
||||||
return $stat;
|
$this->halt('Invalid SQL: '.$Query_String);
|
||||||
}
|
}
|
||||||
|
return $this->Query_ID;
|
||||||
|
}
|
||||||
|
|
||||||
function seek($pos) {
|
function next_record()
|
||||||
$status = msql_data_seek($this->Query_ID, $pos);
|
{
|
||||||
if ($status)
|
$this->Record = msql_fetch_array($this->Query_ID);
|
||||||
$this->Row = $pos;
|
$this->Row += 1;
|
||||||
return;
|
$this->Error = msql_error();
|
||||||
}
|
|
||||||
|
|
||||||
function metadata($table) {
|
$stat = is_array($this->Record);
|
||||||
$count = 0;
|
if (!$stat && $this->Auto_Free)
|
||||||
$id = 0;
|
{
|
||||||
$res = array();
|
msql_free_result($this->Query_ID);
|
||||||
|
$this->Query_ID = 0;
|
||||||
|
}
|
||||||
|
return $stat;
|
||||||
|
}
|
||||||
|
|
||||||
$this->connect();
|
function seek($pos)
|
||||||
$id = @msql_list_fields($this->Database, $table);
|
{
|
||||||
if ($id < 0) {
|
$status = msql_data_seek($this->Query_ID, $pos);
|
||||||
$this->Error = msql_error();
|
if ($status)
|
||||||
$this->halt("Metadata query failed.");
|
{
|
||||||
}
|
$this->Row = $pos;
|
||||||
$count = msql_num_fields($id);
|
}
|
||||||
|
return;
|
||||||
for ($i=0; $i<$count; $i++) {
|
}
|
||||||
$res[$i]["table"] = msql_fieldtable ($id, $i);
|
|
||||||
$res[$i]["name"] = msql_fieldname ($id, $i);
|
|
||||||
$res[$i]["type"] = msql_fieldtype ($id, $i);
|
|
||||||
$res[$i]["len"] = msql_fieldlen ($id, $i);
|
|
||||||
$res[$i]["flags"] = msql_fieldflags ($id, $i);
|
|
||||||
$res["meta"][$res[$i]["name"]] = $i;
|
|
||||||
$res["num_fields"]= $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
msql_free_result($id);
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
function affected_rows() {
|
function metadata($table)
|
||||||
return msql_affected_rows($this->Query_ID);
|
{
|
||||||
}
|
$count = 0;
|
||||||
|
$id = 0;
|
||||||
|
$res = array();
|
||||||
|
|
||||||
function num_rows() {
|
$this->connect();
|
||||||
return msql_num_rows($this->Query_ID);
|
$id = @msql_list_fields($this->Database, $table);
|
||||||
}
|
if ($id < 0)
|
||||||
|
{
|
||||||
|
$this->Error = msql_error();
|
||||||
|
$this->halt('Metadata query failed.');
|
||||||
|
}
|
||||||
|
$count = msql_num_fields($id);
|
||||||
|
|
||||||
function num_fields() {
|
for ($i=0; $i<$count; $i++)
|
||||||
return msql_num_fields($this->Query_ID);
|
{
|
||||||
}
|
$res[$i]['table'] = msql_fieldtable ($id, $i);
|
||||||
|
$res[$i]['name'] = msql_fieldname ($id, $i);
|
||||||
|
$res[$i]['type'] = msql_fieldtype ($id, $i);
|
||||||
|
$res[$i]['len'] = msql_fieldlen ($id, $i);
|
||||||
|
$res[$i]['flags'] = msql_fieldflags ($id, $i);
|
||||||
|
$res['meta'][$res[$i]['name']] = $i;
|
||||||
|
$res['num_fields']= $count;
|
||||||
|
}
|
||||||
|
|
||||||
function nf() {
|
msql_free_result($id);
|
||||||
return $this->num_rows();
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
function np() {
|
function affected_rows()
|
||||||
print $this->num_rows();
|
{
|
||||||
}
|
return msql_affected_rows($this->Query_ID);
|
||||||
|
}
|
||||||
|
|
||||||
function f($Name) {
|
function num_rows()
|
||||||
return $this->Record[$Name];
|
{
|
||||||
}
|
return msql_num_rows($this->Query_ID);
|
||||||
|
}
|
||||||
|
|
||||||
function p($Name) {
|
function num_fields()
|
||||||
print $this->Record[$Name];
|
{
|
||||||
}
|
return msql_num_fields($this->Query_ID);
|
||||||
|
}
|
||||||
function halt($msg) {
|
|
||||||
printf("<b>Database error:</b> %s<br>\n", $msg);
|
function nf()
|
||||||
printf("<b>MSQL Error</b>: %s<br>\n", $this->Error);
|
{
|
||||||
die("Session halted.");
|
return $this->num_rows();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
function np()
|
||||||
|
{
|
||||||
|
print $this->num_rows();
|
||||||
|
}
|
||||||
|
|
||||||
|
function f($Name)
|
||||||
|
{
|
||||||
|
return $this->Record[$Name];
|
||||||
|
}
|
||||||
|
|
||||||
|
function p($Name)
|
||||||
|
{
|
||||||
|
print $this->Record[$Name];
|
||||||
|
}
|
||||||
|
|
||||||
|
function halt($msg)
|
||||||
|
{
|
||||||
|
printf("<b>Database error:</b> %s<br>\n", $msg);
|
||||||
|
printf("<b>MSQL Error</b>: %s<br>\n", $this->Error);
|
||||||
|
die('Session halted.');
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -14,165 +14,201 @@
|
|||||||
\**************************************************************************/
|
\**************************************************************************/
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
class db {
|
class db
|
||||||
var $Host = "";
|
{
|
||||||
var $Database = "";
|
var $Host = '';
|
||||||
var $User = "";
|
var $Database = '';
|
||||||
var $Password = "";
|
var $User = '';
|
||||||
var $UseODBCCursor = 0;
|
var $Password = '';
|
||||||
|
var $UseODBCCursor = 0;
|
||||||
|
|
||||||
var $Link_ID = 0;
|
var $Link_ID = 0;
|
||||||
var $Query_ID = 0;
|
var $Query_ID = 0;
|
||||||
var $Record = array();
|
var $Record = array();
|
||||||
var $Row = 0;
|
var $Row = 0;
|
||||||
|
|
||||||
var $Errno = 0;
|
|
||||||
var $Error = "";
|
|
||||||
|
|
||||||
var $Auto_Free = 0; ## set this to 1 to automatically free results
|
var $Errno = 0;
|
||||||
|
var $Error = '';
|
||||||
|
|
||||||
function connect() {
|
var $Auto_Free = 0; ## set this to 1 to automatically free results
|
||||||
if ( 0 == $this->Link_ID ) {
|
|
||||||
$this->Link_ID=odbc_pconnect($this->Database, $this->User, $this->Password, $this->UseODBCCursor);
|
|
||||||
if (!$this->Link_ID) {
|
|
||||||
$this->halt("Link-ID == false, odbc_pconnect failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function query($Query_String) {
|
|
||||||
$this->connect();
|
|
||||||
|
|
||||||
# printf("<br>Debug: query = %s<br>\n", $Query_String);
|
|
||||||
|
|
||||||
# rei@netone.com.br suggested that we use this instead of the odbc_exec().
|
function connect()
|
||||||
# He is on NT, connecting to a Unix MySQL server with ODBC. -- KK
|
{
|
||||||
# $this->Query_ID = odbc_prepare($this->Link_ID,$Query_String);
|
if ( 0 == $this->Link_ID )
|
||||||
# $this->Query_Ok = odbc_execute($this->Query_ID);
|
{
|
||||||
|
$this->Link_ID=odbc_pconnect($this->Database, $this->User, $this->Password, $this->UseODBCCursor);
|
||||||
$this->Query_ID = odbc_exec($this->Link_ID,$Query_String);
|
if (!$this->Link_ID)
|
||||||
$this->Row = 0;
|
{
|
||||||
odbc_binmode($this->Query_ID, 1);
|
$this->halt('Link-ID == false, odbc_pconnect failed');
|
||||||
odbc_longreadlen($this->Query_ID, 4096);
|
}
|
||||||
|
}
|
||||||
if (!$this->Query_ID) {
|
}
|
||||||
$this->Errno = 1;
|
|
||||||
$this->Error = "General Error (The ODBC interface cannot return detailed error messages).";
|
|
||||||
$this->halt("Invalid SQL: ".$Query_String);
|
|
||||||
}
|
|
||||||
return $this->Query_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
function next_record() {
|
|
||||||
$this->Record = array();
|
|
||||||
$stat = odbc_fetch_into($this->Query_ID, ++$this->Row, &$this->Record);
|
|
||||||
if (!$stat) {
|
|
||||||
if ($this->Auto_Free) {
|
|
||||||
odbc_free_result($this->Query_ID);
|
|
||||||
$this->Query_ID = 0;
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// add to Record[<key>]
|
|
||||||
$count = odbc_num_fields($this->Query_ID);
|
|
||||||
for ($i=1; $i<=$count; $i++)
|
|
||||||
$this->Record[strtolower(odbc_field_name ($this->Query_ID, $i)) ] = $this->Record[ $i - 1 ];
|
|
||||||
}
|
|
||||||
return $stat;
|
|
||||||
}
|
|
||||||
|
|
||||||
function seek($pos) {
|
|
||||||
$this->Row = $pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
function metadata($table) {
|
function query($Query_String)
|
||||||
$count = 0;
|
{
|
||||||
$id = 0;
|
$this->connect();
|
||||||
$res = array();
|
|
||||||
|
|
||||||
$this->connect();
|
# printf("<br>Debug: query = %s<br>\n", $Query_String);
|
||||||
$id = odbc_exec($this->Link_ID, "select * from $table");
|
|
||||||
if (!$id) {
|
|
||||||
$this->Errno = 1;
|
|
||||||
$this->Error = "General Error (The ODBC interface cannot return detailed error messages).";
|
|
||||||
$this->halt("Metadata query failed.");
|
|
||||||
}
|
|
||||||
$count = odbc_num_fields($id);
|
|
||||||
|
|
||||||
for ($i=1; $i<=$count; $i++) {
|
|
||||||
$res[$i]["table"] = $table;
|
|
||||||
$name = odbc_field_name ($id, $i);
|
|
||||||
$res[$i]["name"] = $name;
|
|
||||||
$res[$i]["type"] = odbc_field_type ($id, $name);
|
|
||||||
$res[$i]["len"] = 0; // can we determine the width of this column?
|
|
||||||
$res[$i]["flags"] = ""; // any optional flags to report?
|
|
||||||
}
|
|
||||||
|
|
||||||
odbc_free_result($id);
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
function affected_rows() {
|
|
||||||
return odbc_num_rows($this->Query_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
function num_rows() {
|
|
||||||
# Many ODBC drivers don't support odbc_num_rows() on SELECT statements.
|
|
||||||
$num_rows = odbc_num_rows($this->Query_ID);
|
|
||||||
//printf ($num_rows."<br>");
|
|
||||||
|
|
||||||
# This is a workaround. It is intended to be ugly.
|
# rei@netone.com.br suggested that we use this instead of the odbc_exec().
|
||||||
if ($num_rows < 0) {
|
# He is on NT, connecting to a Unix MySQL server with ODBC. -- KK
|
||||||
$i=10;
|
# $this->Query_ID = odbc_prepare($this->Link_ID,$Query_String);
|
||||||
while (odbc_fetch_row($this->Query_ID, $i))
|
# $this->Query_Ok = odbc_execute($this->Query_ID);
|
||||||
$i*=10;
|
|
||||||
|
|
||||||
$j=0;
|
$this->Query_ID = odbc_exec($this->Link_ID,$Query_String);
|
||||||
while ($i!=$j) {
|
$this->Row = 0;
|
||||||
$k= $j+intval(($i-$j)/2);
|
odbc_binmode($this->Query_ID, 1);
|
||||||
if (odbc_fetch_row($this->Query_ID, $k))
|
odbc_longreadlen($this->Query_ID, 4096);
|
||||||
$j=$k;
|
|
||||||
else
|
|
||||||
$i=$k;
|
|
||||||
if (($i-$j)==1) {
|
|
||||||
if (odbc_fetch_row($this->Query_ID, $i))
|
|
||||||
$j=$i;
|
|
||||||
else
|
|
||||||
$i=$j;
|
|
||||||
};
|
|
||||||
//printf("$i $j $k <br>");
|
|
||||||
};
|
|
||||||
$num_rows=$i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $num_rows;
|
if (!$this->Query_ID)
|
||||||
}
|
{
|
||||||
|
$this->Errno = 1;
|
||||||
function num_fields() {
|
$this->Error = 'General Error (The ODBC interface cannot return detailed error messages).';
|
||||||
return count($this->Record)/2;
|
$this->halt('Invalid SQL: '.$Query_String);
|
||||||
}
|
}
|
||||||
|
return $this->Query_ID;
|
||||||
|
}
|
||||||
|
|
||||||
function nf() {
|
function next_record()
|
||||||
return $this->num_rows();
|
{
|
||||||
}
|
$this->Record = array();
|
||||||
|
$stat = odbc_fetch_into($this->Query_ID, ++$this->Row, &$this->Record);
|
||||||
function np() {
|
if (!$stat)
|
||||||
print $this->num_rows();
|
{
|
||||||
}
|
if ($this->Auto_Free)
|
||||||
|
{
|
||||||
function f($Field_Name) {
|
odbc_free_result($this->Query_ID);
|
||||||
return $this->Record[strtolower($Field_Name)];
|
$this->Query_ID = 0;
|
||||||
}
|
};
|
||||||
|
}
|
||||||
function p($Field_Name) {
|
else
|
||||||
print $this->f($Field_Name);
|
{
|
||||||
}
|
// add to Record[<key>]
|
||||||
|
$count = odbc_num_fields($this->Query_ID);
|
||||||
function halt($msg) {
|
for ($i=1; $i<=$count; $i++)
|
||||||
printf("<b>Database error:</b> %s<br>\n", $msg);
|
{
|
||||||
printf("<b>ODBC Error</b>: %s (%s)<br>\n",
|
$this->Record[strtolower(odbc_field_name ($this->Query_ID, $i)) ] = $this->Record[ $i - 1 ];
|
||||||
$this->Errno,
|
}
|
||||||
$this->Error);
|
}
|
||||||
die("Session halted.");
|
return $stat;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
function seek($pos)
|
||||||
|
{
|
||||||
|
$this->Row = $pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
function metadata($table)
|
||||||
|
{
|
||||||
|
$count = 0;
|
||||||
|
$id = 0;
|
||||||
|
$res = array();
|
||||||
|
|
||||||
|
$this->connect();
|
||||||
|
$id = odbc_exec($this->Link_ID, "select * from $table");
|
||||||
|
if (!$id)
|
||||||
|
{
|
||||||
|
$this->Errno = 1;
|
||||||
|
$this->Error = 'General Error (The ODBC interface cannot return detailed error messages).';
|
||||||
|
$this->halt('Metadata query failed.');
|
||||||
|
}
|
||||||
|
$count = odbc_num_fields($id);
|
||||||
|
|
||||||
|
for ($i=1; $i<=$count; $i++)
|
||||||
|
{
|
||||||
|
$res[$i]['table'] = $table;
|
||||||
|
$name = odbc_field_name ($id, $i);
|
||||||
|
$res[$i]['name'] = $name;
|
||||||
|
$res[$i]['type'] = odbc_field_type ($id, $name);
|
||||||
|
$res[$i]['len'] = 0; // can we determine the width of this column?
|
||||||
|
$res[$i]['flags'] = ''; // any optional flags to report?
|
||||||
|
}
|
||||||
|
odbc_free_result($id);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function affected_rows()
|
||||||
|
{
|
||||||
|
return odbc_num_rows($this->Query_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function num_rows()
|
||||||
|
{
|
||||||
|
# Many ODBC drivers don't support odbc_num_rows() on SELECT statements.
|
||||||
|
$num_rows = odbc_num_rows($this->Query_ID);
|
||||||
|
//printf ($num_rows."<br>");
|
||||||
|
|
||||||
|
# This is a workaround. It is intended to be ugly.
|
||||||
|
if ($num_rows < 0)
|
||||||
|
{
|
||||||
|
$i=10;
|
||||||
|
while (odbc_fetch_row($this->Query_ID, $i))
|
||||||
|
{
|
||||||
|
$i*=10;
|
||||||
|
}
|
||||||
|
|
||||||
|
$j=0;
|
||||||
|
while ($i!=$j)
|
||||||
|
{
|
||||||
|
$k= $j+intval(($i-$j)/2);
|
||||||
|
if (odbc_fetch_row($this->Query_ID, $k))
|
||||||
|
{
|
||||||
|
$j=$k;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$i=$k;
|
||||||
|
}
|
||||||
|
if (($i-$j)==1)
|
||||||
|
{
|
||||||
|
if (odbc_fetch_row($this->Query_ID, $i))
|
||||||
|
{
|
||||||
|
$j=$i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$i=$j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//printf("$i $j $k <br>");
|
||||||
|
}
|
||||||
|
$num_rows=$i;
|
||||||
|
}
|
||||||
|
return $num_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
function num_fields()
|
||||||
|
{
|
||||||
|
return count($this->Record)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function nf()
|
||||||
|
{
|
||||||
|
return $this->num_rows();
|
||||||
|
}
|
||||||
|
|
||||||
|
function np()
|
||||||
|
{
|
||||||
|
print $this->num_rows();
|
||||||
|
}
|
||||||
|
|
||||||
|
function f($Field_Name)
|
||||||
|
{
|
||||||
|
return $this->Record[strtolower($Field_Name)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function p($Field_Name)
|
||||||
|
{
|
||||||
|
print $this->f($Field_Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function halt($msg)
|
||||||
|
{
|
||||||
|
printf("<b>Database error:</b> %s<br>\n", $msg);
|
||||||
|
printf("<b>ODBC Error</b>: %s (%s)<br>\n",
|
||||||
|
$this->Errno,
|
||||||
|
$this->Error);
|
||||||
|
die('Session halted.');
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -17,18 +17,19 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
class db {
|
class db
|
||||||
var $Host = "";
|
{
|
||||||
var $Database = "";
|
var $Host = '';
|
||||||
var $User = "";
|
var $Database = '';
|
||||||
var $Password = "";
|
var $User = '';
|
||||||
|
var $Password = '';
|
||||||
|
|
||||||
var $Link_ID = 0;
|
var $Link_ID = 0;
|
||||||
var $Query_ID = 0;
|
var $Query_ID = 0;
|
||||||
var $Record = array();
|
var $Record = array();
|
||||||
var $Row;
|
var $Row;
|
||||||
|
|
||||||
var $Auto_Free = 0; ## Set this to 1 for automatic sybase_free_result()
|
var $Auto_Free = 0; ## Set this to 1 for automatic sybase_free_result()
|
||||||
|
|
||||||
function connect()
|
function connect()
|
||||||
{
|
{
|
||||||
@ -45,104 +46,122 @@ class db {
|
|||||||
}
|
}
|
||||||
if (!$this->Link_ID)
|
if (!$this->Link_ID)
|
||||||
{
|
{
|
||||||
$this->halt('Link-ID == false, '.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'')..'connect failed");
|
$this->halt('Link-ID == false, '.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'')..'connect failed');
|
||||||
}
|
}
|
||||||
if(!sybase_select_db($this->Database, $this->Link_ID))
|
if(!sybase_select_db($this->Database, $this->Link_ID))
|
||||||
{
|
{
|
||||||
$this->halt("cannot use database ".$this->Database);
|
$this->halt('cannot use database '.$this->Database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function query($Query_String) {
|
function query($Query_String)
|
||||||
$this->connect();
|
{
|
||||||
|
$this->connect();
|
||||||
|
|
||||||
# printf("Debug: query = %s<br>\n", $Query_String);
|
# printf("Debug: query = %s<br>\n", $Query_String);
|
||||||
|
|
||||||
$this->Query_ID = sybase_query($Query_String,$this->Link_ID);
|
$this->Query_ID = sybase_query($Query_String,$this->Link_ID);
|
||||||
$this->Row = 0;
|
$this->Row = 0;
|
||||||
if (!$this->Query_ID) {
|
if (!$this->Query_ID)
|
||||||
$this->halt("Invalid SQL: ".$Query_String);
|
{
|
||||||
}
|
$this->halt('Invalid SQL: '.$Query_String);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->Query_ID;
|
return $this->Query_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
function next_record() {
|
function next_record()
|
||||||
$this->Record = sybase_fetch_array($this->Query_ID);
|
{
|
||||||
$this->Row += 1;
|
$this->Record = sybase_fetch_array($this->Query_ID);
|
||||||
|
$this->Row += 1;
|
||||||
|
|
||||||
$stat = is_array($this->Record);
|
$stat = is_array($this->Record);
|
||||||
if (!$stat && $this->Auto_Free) {
|
if (!$stat && $this->Auto_Free)
|
||||||
sybase_free_result($this->Query_ID);
|
{
|
||||||
$this->Query_ID = 0;
|
sybase_free_result($this->Query_ID);
|
||||||
}
|
$this->Query_ID = 0;
|
||||||
return $stat;
|
}
|
||||||
}
|
return $stat;
|
||||||
|
}
|
||||||
|
|
||||||
function seek($pos) {
|
function seek($pos)
|
||||||
$status = sybase_data_seek($this->Query_ID, $pos);
|
{
|
||||||
if ($status)
|
$status = sybase_data_seek($this->Query_ID, $pos);
|
||||||
$this->Row = $pos;
|
if ($status)
|
||||||
return;
|
{
|
||||||
}
|
$this->Row = $pos;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function metadata($table) {
|
function metadata($table)
|
||||||
$count = 0;
|
{
|
||||||
$id = 0;
|
$count = 0;
|
||||||
$res = array();
|
$id = 0;
|
||||||
|
$res = array();
|
||||||
|
|
||||||
$this->connect();
|
$this->connect();
|
||||||
$result = $this->query("exec sp_columns $table");
|
$result = $this->query("exec sp_columns $table");
|
||||||
if ($result < 0) {
|
if ($result < 0)
|
||||||
$this->Errno = 1;
|
{
|
||||||
$this->Error = "Metadata query failed";
|
$this->Errno = 1;
|
||||||
$this->halt("Metadata query failed.");
|
$this->Error = 'Metadata query failed';
|
||||||
}
|
$this->halt('Metadata query failed.');
|
||||||
$count = sybase_num_rows($result);
|
}
|
||||||
|
$count = sybase_num_rows($result);
|
||||||
|
|
||||||
for ($i=0; $i<$count; $i++) {
|
for ($i=0; $i<$count; $i++)
|
||||||
$res[$i]["table"] = $table ;
|
{
|
||||||
$res[$i]["name"] = sybase_result ($result, $i, "COLUMN_NAME");
|
$res[$i]['table'] = $table ;
|
||||||
$res[$i]["type"] = sybase_result ($result, $i, "TYPE_NAME");
|
$res[$i]['name'] = sybase_result ($result, $i, 'COLUMN_NAME');
|
||||||
$res[$i]["len"] = sybase_result ($result, $i, "LENGTH");
|
$res[$i]['type'] = sybase_result ($result, $i, 'TYPE_NAME');
|
||||||
$res[$i]["position"] = sybase_result ($result, $i, "ORDINAL_POSITION");
|
$res[$i]['len'] = sybase_result ($result, $i, 'LENGTH');
|
||||||
$res[$i]["flags"] = sybase_result ($result, $i, "REMARKS");
|
$res[$i]['position'] = sybase_result ($result, $i, 'ORDINAL_POSITION');
|
||||||
|
$res[$i]['flags'] = sybase_result ($result, $i, 'REMARKS');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function affected_rows() {
|
function affected_rows()
|
||||||
return sybase_affected_rows($this->Query_ID);
|
{
|
||||||
}
|
return sybase_affected_rows($this->Query_ID);
|
||||||
|
}
|
||||||
|
|
||||||
function num_rows() {
|
function num_rows()
|
||||||
return sybase_num_rows($this->Query_ID);
|
{
|
||||||
}
|
return sybase_num_rows($this->Query_ID);
|
||||||
|
}
|
||||||
|
|
||||||
function num_fields() {
|
function num_fields()
|
||||||
return sybase_num_fields($this->Query_ID);
|
{
|
||||||
}
|
return sybase_num_fields($this->Query_ID);
|
||||||
|
}
|
||||||
|
|
||||||
function nf() {
|
function nf()
|
||||||
return $this->num_rows();
|
{
|
||||||
}
|
return $this->num_rows();
|
||||||
|
}
|
||||||
|
|
||||||
function np() {
|
function np()
|
||||||
print $this->num_rows();
|
{
|
||||||
}
|
print $this->num_rows();
|
||||||
|
}
|
||||||
|
|
||||||
function f($Name) {
|
function f($Name)
|
||||||
return $this->Record[$Name];
|
{
|
||||||
}
|
return $this->Record[$Name];
|
||||||
|
}
|
||||||
|
|
||||||
function p($Name) {
|
function p($Name)
|
||||||
print $this->Record[$Name];
|
{
|
||||||
}
|
print $this->Record[$Name];
|
||||||
|
}
|
||||||
function halt($msg) {
|
|
||||||
printf("<b>Database error:</b> %s<br>\n", $msg);
|
function halt($msg)
|
||||||
printf("<b>Sybase Error</b><br>\n");
|
{
|
||||||
die("Session halted.");
|
printf("<b>Database error:</b> %s<br>\n", $msg);
|
||||||
}
|
printf("<b>Sybase Error</b><br>\n");
|
||||||
}
|
die("Session halted.");
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user