\n"; } ini_set('mssql.datetimeconvert', 0); //datetimes returned with milliseconds, which is not a supported format $data = mssql_query($sql, $connection); } elseif($GLOBALS['db_type'] == "postgresql") { $data = pg_query($connection, $sql); } else { $data = odbc_exec($connection, $sql); } return $data; } /* db1_escape * Creates an escaped string for mssql. Note that this should probably not be run more than once on the same string; * it's not smart enough to detect already-escaped single quotes * Param $string The string to be escaped * Returns The escaped string */ function db1_escape($string) { $estring = $string; if($GLOBALS['db_type'] == "postgresql") { $estring = pg_escape_string($string); } else { $estring = str_replace("'", "''", $string); } return $estring; } /* db1_fetch * Call this multiple times to get multiple rows * Param $result A mssql or odbc resultset * Returns the next row in the resultset */ function db1_fetch($result) { $row = null; if($GLOBALS['db_type'] == "mssql") { $row = mssql_fetch_row($result); } elseif($GLOBALS['db_type'] == "postgresql") { $row = pg_fetch_row($result); } else { $row = odbc_fetch_row($result); } return $row; } /* db1_result * Returns the contents of one field from a resultset * Param $result An active resultset * Param $field The field name to retrieve * Param $row The row to look in; defaults to the first row (some code uses 1 for first row, but should be 0) * Returns The value at $row[$field] in the resultset */ function db1_result($result, $field, $row=0) { if($GLOBALS['db_type'] == "mssql") { if(isset($GLOBALS['debug']) && $GLOBALS['debug'] == 'Y') { echo $result.'::'.$row.'::'.$field; } $row--; //correct misuse of 1 if($row < 0) { $row = 0; } $db_result=mssql_result($result, $row, $field); } elseif($GLOBALS['db_type'] == "postgresql") { $assoc = pg_fetch_assoc($result, $row); $db_result = $assoc[$field]; } else { $db_result=odbc_result($result,$field); } return $db_result; } /* db1_fetch_object * Returns a row from a resultset in associative array form * Param $result An active resultset * Param $rownumber The row to return, defaults to the first active row * Returns The row in associative array form * */ function db1_fetch_object($result,$rownumber=1) { if($GLOBALS['db_type'] == "mssql") { $db_object=mssql_fetch_object($result); } elseif($GLOBALS['db_type'] == "postgresql") { $db_object = pg_fetch_assoc($result, $rownumber); } else { $db_object=odbc_fetch_object($result,$rownumber); } return $db_object; } /* db1_num_rows * Returns the number of rows in a resultset * Param $result The active resultset * Returns The number of rows in the resultset */ function db1_num_rows($result) { if($GLOBALS['db_type'] == "mssql") { $db_num=mssql_num_rows($result); } elseif($GLOBALS['db_type'] == "postgresql") { $db_num = pg_num_rows($result); //this is roughed-in only //our ODBC driver does not play well with MSSQL so odbc_num_rows is always -1 on INSERT/UPDATE and works in special cases only with SELECT } elseif($GLOBALS['rowcount_hack'] == "Y") { //need $connection $result=$this->db1_query($connection, "select @@error 'errors', @@ROWCOUNT 'rowcount'"); //need to get object of result, set a global $errors=errors for debugging and send back $db_num=rowcount; } else { $db_num=odbc_num_rows($result); } return $db_num; } /* db1_getDBData * Commented out because connectClass() is not yet supported. * * function db1_getDBData($DB=false) { if(!defined($GLOBALS['db_conn'])) { die("ERROR: Database variables not set"); } global $row; $this->connectClass(); #$this->openProducts($isbn); $this->close(); } */ /* db1_free_result * Frees a resultset so that it can be used again if necessary * Note that this will be done by the garbage collector automatically; it only needs to be called if you are using the same * resultset twice or more per function in order to ensure correct contents of the resultset. * Param $resultset The resultset to free * Returns true */ function db1_free_result($resultset) { if($GLOBALS['db_type'] == "mssql") { mssql_free_result($resultset); } elseif($GLOBALS['db_type'] == "postgresql") { pg_free_result($resultset); } else { ; } return true; } # LHH - Relocated from old db_conn.php # odbc_fetch_object() is not defined in the following config # Red Hat Linux 8.0, PHP 4.2.2 function odbc_fetch_object($res) { $obj = new stdClass(); $data_array = array(); if (!odbc_fetch_into($res, $data_array)) { return 0; } $num_fields = odbc_num_fields($res); for ($i = 0;$i < $num_fields; $i++) { $name = odbc_field_name($res, $i + 1); if (!$name) { return 0; } $obj->{$name} = $data_array[$i]; } return $obj; } /* below is class structure for future class DB { var $db; function DB($alias=false) { if(!$alias) { die("ERROR: Database not specified"); } ##Array of databases## # $db = array('ALIAS OF DB'=>array('username'=>"USERNAME", 'password'=>"PASSWORD", 'server'=>"IP OR NAME", 'dsn'=>"ACTUAL NAME OF DB", 'method'=>"odbc, mssql")); $db = array( //OLD'mulleresterl_linkDB'=>array('username'=>"eicuser", 'password'=>"p1gg1b8", 'server'=>"198.181.209.96:1433", 'dsn'=>"EIC_DB", 'method'=>"odbc"), 'mulleresterl_linkDB'=>array('username'=>"eicuser", 'password'=>"p1gg1b8", 'server'=>"198.181.209.1:1433", 'dsn'=>"EIC_DB", 'server_name'=>"Elsstlsqlp003", 'method'=>"odbc"), ); $this->db = $db; #allows $DB->db["ALIAS OF DB"]["dsn"] $this->DB = $db[$alias]; #typical new DB("ALIAS OF DB"); $DB->DB["dsn"] } function connectClass() { global $strings, $res; #odbc_connect($DB->DB["dsn"], $DB->DB["username"], $DB->DB["password"]); if($DB->DB["method"] == "mssql") { $res = mssql_connect($DB->DB["server"], $DB->DB["username"], $DB->DB["password"]) or die("ERROR: Database Connection Failed"); } else { $res = odbc_connect($DB->DB["dsn"], $DB->DB["username"], $DB->DB["password"]) or die("ERROR: Database Connection Failed"); } } */ ?>