longish bug report (no 2 liner-sorry)
| From: | Thies C . Arntzen | Date: | Tue, 01 Feb 2000 16:21:20 +0000 |
| Subject: | longish bug report (no 2 liner-sorry) | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-9629@lists.php.net to get a copy of this message | ||
hi,
script is attached (needs oracle to work but the interesting
lines are easy to spot -> search for var_dump())
...
$allnames = array();
$allvals = array();
var_dump($allvals,$nobindfields);
reset($nobindfields);
while (list($fieldname,$fieldvalue) = each($nobindfields))
{ $allnames[] = $fieldname;
$allvals[] = $fieldvalue;
}
var_dump($allvals,$nobindfields);
...
(the whole script is included)
the "right" output would be:
X-Powered-By: PHP/4.0b4-dev
Content-Type: text/html
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
currently it outputs:
X-Powered-By: PHP/4.0b4-dev
Content-Type: text/html
array(0) {
}
array(0) {
}
i:0
array(0) {
}
<br>
<b>Warning</b>: Bad arguments to implode() in <b>ora.php</b> on line
<b>676</b><br>
so somehow $allvals changes it's type?!?!
we also get all kinds of nice FMR, FMW etc with it..
**** Purify instrumented ./php (pid 13313 at Tue Feb 1 17:18:24 2000) * Purify 4.5 Solaris 2, Copyright (C) 1992-1999 Rational Software Corp. All rights reserved. * For contact information type: "purify -help" * For TTY output, use the option "-windows=no" * Command-line: ./php ora.php * Options settings: -purify \ -purify-home=/dot/utility/pure/purify-4.5-solaris2 -threads=yes \ -use-internal-locks=yes -thread_stack_change=0x4000 -mt_safe_malloc=yes **** Purify instrumented ./php (pid 13313) **** FMR: Free memory read: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:218] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Reading 2 bytes from 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** FMW: Free memory write: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:218] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Writing 2 bytes to 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** FMR: Free memory read: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:219] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Reading 2 bytes from 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** FMR: Free memory read: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:222] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Reading 2 bytes from 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** ABR: Array bounds read: * This is occurring while in: shutdown_executor [zend_execute_API.c:137] zend_deactivate [zend.c:464] php_request_shutdown [main.c:733] main [cgi_main.c:542] _start [crt1.o] * Reading 2 bytes from 0x38d042 in the heap. * Address 0x38d042 is 135 bytes past end of a malloc'd block at 0x38cf60 of 92 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] zend_hash_add_or_update [zend_hash.c:232] zend_fetch_var_address [libphp4.a] execute [libphp4.a] execute [libphp4.a] **** Purify instrumented ./php (pid 13313) **** Current file descriptors in use: 7 FIU: file descriptor 0: <stdin> FIU: file descriptor 1: <stdout> FIU: file descriptor 2: <stderr> FIU: file descriptor 3: "/etc/.name_service_door", O_RDONLY * File info: ?r--r--r-- 1 root root 0 Jul 30 1998 * This file descriptor was allocated from: _open64 [libc.so.1] _nsc_trydoorcall [libc.so.1] getpwuid_r [libc.so.1] snigun [sniq.c] nigconcbs [nigcon.c] osncon [nigcon.c] FIU: file descriptor 4: "/etc/mnttab", O_RDONLY * File info: srw-rw-rw- 0 root root 0 Feb 1 17:18 * This file descriptor was allocated from: _open [libc.so.1] _endopen [libc.so.1] fopen [libc.so.1] getdevinfo [getcwd.c] getcwd [libc.so.1] snlfncdir [snlfn.c] FIU: file descriptor 26: <reserved for Purify internal use> FIU: file descriptor 27: <reserved for Purify internal use> **** Purify instrumented ./php (pid 13313) **** Purify: Searching for all memory leaks... Memory leaked: 591 bytes (0.684%); potentially leaked: 0 bytes (0%) MLK: 380 bytes leaked in 5 blocks * This memory was allocated from: malloc [rtlib.o] zend_hash_add_or_update [zend_hash.c:242] zend_register_functions [zend_API.c:733] register_internal_class [zend_API.c:886] php_minit_oci [oci8.c:365] zend_startup_module [zend_API.c:677] * Block of 76 bytes (5 times); last block at 0x371518 MLK: 211 bytes leaked in 5 blocks * This memory was allocated from: malloc [rtlib.o] zend_hash_add_or_update [zend_hash.c:232] zend_register_functions [zend_API.c:733] register_internal_class [zend_API.c:886] php_minit_oci [oci8.c:365] zend_startup_module [zend_API.c:677] * Block of 47 bytes at 0x371130 * Block of 44 bytes at 0x371378 * Block of 40 bytes (3 times); last block at 0x371498 Purify Heap Analysis (combining suppressed and unsuppressed blocks) Blocks Bytes Leaked 10 591 Potentially Leaked 1 4104 In-Use 76 81656 ---------------------------------------- Total Allocated 87 86351 **** Purify instrumented ./php (pid 13313) **** Thread Summary : 1 threads in existence * Thread 0 [main thread] Stack: (0xeffff7b8 0xf0000000), size = 0x848 **** Purify instrumented ./php (pid 13313) **** * Program exited with status code 0. * 5 access errors, 5 total occurrences. * 591 bytes leaked. * 0 bytes potentially leaked. * Basic memory usage (including Purify overhead): 2939647 code 248476 data/bss 1056772 heap (peak use) 1848 stack * Shared library memory usage (including Purify overhead): 2196 solaris2_threads.so_pure_p3_c0_450_56 (shared code) 8556 solaris2_threads.so_pure_p3_c0_450_56 (private data) 8252504 libclntsh.so.1.0_pure_p3_c0_450_56 (shared code) 468880 libclntsh.so.1.0_pure_p3_c0_450_56 (private data) 140125 libm.so.1_pure_p3_c0_450_56 (shared code) 1332 libm.so.1_pure_p3_c0_450_56 (private data) 28919 libpam.so.1_pure_p3_c0_450_56 (shared code) 3172 libpam.so.1_pure_p3_c0_450_56 (private data) 2036 libdl.so.1_pure_p3_c0_450_56 (shared code) 4 libdl.so.1_pure_p3_c0_450_56 (private data) 82251 libresolv.so.2_pure_p3_c0_450_56 (shared code) 16296 libresolv.so.2_pure_p3_c0_450_56 (private data) 41730 libsocket.so.1_pure_p3_c0_450_56 (shared code) 3312 libsocket.so.1_pure_p3_c0_450_56 (private data) 733710 libnsl.so.1_pure_p3_c0_450_56 (shared code) 54408 libnsl.so.1_pure_p3_c0_450_56 (private data) 961297 libc.so.1_pure_p3_c0_450_56 (shared code) 30916 libc.so.1_pure_p3_c0_450_56 (private data) 11766 libinternal_stubs.so.1 (shared code) 832 libinternal_stubs.so.1 (private data) 35730 libaio.so.1_pure_p3_c0_450_56 (shared code) 6388 libaio.so.1_pure_p3_c0_450_56 (private data) 16272 libmp.so.2_pure_p3_c0_450_56 (shared code) 836 libmp.so.2_pure_p3_c0_450_56 (private data) <?php // -*- C++ -*- $GLOBALS[ "DBView_DB" ] = -1; $GLOBALS[ "DBView_Cursors" ] = array(); $GLOBALS[ "DBView_CurCnt" ] = 0; $GLOBALS[ "DBView_SawError" ] = false; $GLOBALS[ "DBView_Registered" ] = false; // }}} // {{{ _DBView_Log($what) function _DBView_Log($what) { $logfile = "/dot/logs/dbview.log"; clearstatcache(); if (! file_exists($logfile)) return; $fd = @fopen($logfile,"a"); if ($fd) { $what ="<" . getmypid() ." " . date("d.m.Y-H:i:s") . "> " . $what; fputs($fd,$what . "\n"); fclose($fd); } } // }}} // {{{ DBView_GetLogin(&$login) function DBView_GetLogin(&$login) { $login = array("user" =>"digicol", "password" =>"digicol", "service" =>"", "connect" =>"digicol/digicol"); // XXX maybe allow the "user" to specify the logint in dcinst?? /* if (isset($GLOBALS[ "DOCUMENT_ROOT" ])) { $filename = $GLOBALS[ "DOCUMENT_ROOT" ]."/include/sqllogin.htd"; $err = HTDL_Source($filename,&$htdlvars); if ($err == 0) if (is_array($htdlvars) && isset($htdlvars[ "sql" ])) { if (isset($htdlvars[ "sql" ][ "uid" ])) { $login[ "user" ] = $htdlvars[ "sql" ][ "uid" ]; $login[ "connect" ] = $login[ "user" ]; } if (isset($htdlvars[ "sql" ][ "pwd" ])) { $login[ "password" ] = $htdlvars[ "sql" ][ "pwd" ]; $login[ "connect" ] .= '/'.$login[ "password" ]; } if (isset($htdlvars[ "sql" ][ "service" ])) { if ($htdlvars[ "sql" ][ "service" ] != "*") { $login[ "service" ] = $htdlvars[ "sql" ][ "service" ]; $login[ "connect" ] .= '@'.$login[ "service" ]; } } } } */ return 0; } // }}} // {{{ _DBView_Error($mycurs,$func) function _DBView_Error($mycurs,$func) { _DBView_Log("Error: ".$func." - (".@ora_errorcode($mycurs).") <".@ora_error($mycurs).">"); $GLOBALS[ "DBView_SawError" ] = true; } // }}} // {{{ DBView_CloseDB() function DBView_CloseDB() { for ($inx = 0; $inx < $GLOBALS[ "DBView_CurCnt" ]; $inx++) @ora_close($GLOBALS[ "DBView_Cursors" ][ $inx ]); if ($GLOBALS[ "DBView_DB" ] != -1) @ora_logoff($GLOBALS[ "DBView_DB" ]); $GLOBALS[ "DBView_DB" ] = -1; } // }}} // {{{ DBView_GetDB() function DBView_GetDB() { if ($GLOBALS[ "DBView_DB" ] != -1) return $GLOBALS[ "DBView_DB" ]; $GLOBALS[ "DBView_Cursors" ] = array(); $GLOBALS[ "DBView_CurCnt" ] = 0; if (! $GLOBALS[ "DBView_Registered" ]) { register_shutdown_function("DBView_CloseDB"); $GLOBALS[ "DBView_Registered" ] = true; } DBView_GetLogin(&$login); $GLOBALS[ "DBView_DB" ] = @ora_logon($login[ "connect" ],""); if ($GLOBALS[ "DBView_DB" ] == false) { $GLOBALS[ "DBView_DB" ] = -1; _DBView_Log("DBView_GetDB: ora_logon failed"); return -1; } return $GLOBALS[ "DBView_DB" ]; } // }}} // {{{ DBView_Close($curs) function DBView_Close($curs) { if ($GLOBALS[ "DBView_SawError" ]) DBView_Ping(); if ($GLOBALS[ "DBView_DB" ] == -1) return -2; $GLOBALS[ "DBView_Cursors" ][ $GLOBALS[ "DBView_CurCnt" ] ] = $curs; $GLOBALS[ "DBView_CurCnt" ]++; $res = @ora_commit($GLOBALS[ "DBView_DB" ]); if ($res == false) { _DBView_Error($GLOBALS[ "DBView_DB" ],"commit"); return -1; } return 0; } // }}} // {{{ DBView_Ping() function DBView_Ping() { $db = DBView_GetDB(); if ($db == -1) { _DBView_Log("DBView_Ping: DBView_GetDB failed"); return -1; } $curs = @ora_open($db); if (! $curs) { _DBView_Log("DBView_Ping: ora_open failed"); DBView_CloseDB(); return -1; } $ok = @ora_parse($curs,"select sysdate from dual"); if (! $ok) { _DBView_Log("DBView_Ping: ora_parse failed"); @ora_close($curs); DBView_CloseDB(); return -2; } $ok = @ora_exec($curs); if (! $ok) { _DBView_Log("DBView_Ping: ora_exec failed"); @ora_close($curs); return -3; } @ora_close($curs); $GLOBALS[ "DBView_SawError" ] = false; _DBView_Log("DBView_Ping: success"); return 0; } // }}} // {{{ DBView_GetCursor() function DBView_GetCursor() { if ($GLOBALS[ "DBView_CurCnt" ] > 0) { $GLOBALS[ "DBView_CurCnt" ]--; $cur = $GLOBALS[ "DBView_Cursors" ][ $GLOBALS[ "DBView_CurCnt" ]]; return $cur; } $mydb = DBView_GetDB(); if ($mydb == -1) { return -1; $GLOBALS[ "DBView_SawError" ] = true; } $cur = @ora_open($mydb); if ($cur == false) { _DBView_Error($mydb,"open"); return -2; } return $cur; } // }}} // {{{ DBView_NextDC4Seq() function DBView_NextDC4Seq() { $tmp = array(); DBView_Extract("select DC4SEQ.nextval from DUAL",0,"NEXTVAL",&$tmp); return $tmp[ 0 ]; } // }}} // {{{ DBView_Fetch($mycurs,&$cols) function DBView_Fetch($mycurs,&$cols) { $res = @ora_fetch_into($mycurs,&$cols,ORA_FETCHINTO_NULLS | ORA_FETCHINTO_ASSOC); if ($res == false) { $code = ora_errorcode($mycurs); if ($code != 1403) // ORA-01403: no data found - marks end of cursor - so it's not an error _DBView_Error($mycurs,"fetch_into"); return -1 * $code; } return 0; } // }}} // {{{ DBView_Skip($mycurs,$rows) function DBView_Skip($mycurs,$rows) { _DBView_Log("DBView_Skip: ".$rows); while ($rows > 0) { $res = @ora_fetch($mycurs); if ($res == false) { _DBView_Error($mycurs,"fetch"); return -1; } $rows--; } return 0; } // }}} // {{{ _DBView_Bind($mycurs,&$bindfields,$marker,$forcein) function _DBView_Bind($mycurs,&$bindfields,$marker,$forcein) { $result = array(); if (is_array($bindfields)) { reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) { $p = explode("#", $fieldname); if (count($p) == 2) { $fname = $p[ 0 ]; $flag = $p[ 1 ]; } else { $fname = $fieldname; if ($forcein) $flag = "in"; else $flag = "inout"; } $globname = "__".$marker."__".$fname; // _DBView_Log("_DBView_Bind <".$fieldname."><".$flag."><".$fname.">=(".strlen($fieldvalue).")<".$fieldvalue.">"); switch ($flag) { case "in": if (strlen($fieldvalue) > 65000) _DBView_Log("DBView_Bind: value for <".$fname."> is larger 64K!"); $res = @ora_bind($mycurs,$globname,":".$fname,strlen($fieldvalue),ORA_BIND_IN); break; case "out": $res = @ora_bind($mycurs,$globname,":".$fname,65000,ORA_BIND_OUT); break; default: $res = @ora_bind($mycurs,$globname,":".$fname,65000,ORA_BIND_INOUT); break; } if ($res != true) _DBView_Error($mycurs,"bind"); $GLOBALS[ $globname ] = $fieldvalue; $result[ $fieldname ] = $globname; } } return $result; } // }}} // {{{ _DBView_Exec($mycurs) function _DBView_Exec($mycurs) { $res = @ora_exec($mycurs); if ($res == true) return 0; _DBView_Error($mycurs,"exec"); return -1 * ora_errorcode($mycurs); } // }}} // {{{ DBView_Parse($sql) function DBView_Parse(&$sql) { $mycurs = DBView_GetCursor(); if ($mycurs < 0) return $mycurs; $res = @ora_parse($mycurs,&$sql); if (! $res) { _DBView_Error($mycurs,"parse 1 <".$sql.">"); DBView_Close($mycurs); $mycurs = DBView_GetCursor(); if ($mycurs < 0) return $mycurs; $res = @ora_parse($mycurs,&$sql); if (! $res) { _DBView_Error($mycurs,"parse 2 <".$sql.">"); return -1 * ora_errorcode($mycurs); } } return $mycurs; } // }}} // {{{ DBView_Open($sql,&$numcols,$bindfields = 0) function DBView_Open($sql,&$numcols,$bindfields = 0) { $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$bindfields,"O",true); _DBView_Log("DBView_Open: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $numcols = @ora_numcols($mycurs); return $mycurs; } // }}} // {{{ DBView_Load($sql,$result = 0,$bindfields = 0) function DBView_Load($sql,$result = 0,$bindfields = 0) { // API compatibility: New code should use a referenced variable if ($result == 0) $retresult = true; else $retresult = false; $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$bindfields,"L",true); _DBView_Log("DBView_Load: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $numcol = @ora_numcols($mycurs); $result = array(); $colnames = array(); for ($inx = 0; $inx < $numcol; $inx++) { $colname[ $inx ] = @ora_columnname($mycurs,$inx); $result[ $colname[ $inx ] ] = array(); } while (@ora_fetch($mycurs)) for ($inx = 0; $inx < $numcol; $inx++) $result[ $colname[ $inx ] ][ ] = @ora_getcolumn($mycurs,$inx); $code = @ora_errorcode($mycurs); if ($code != 1403) // ORA-01403: no data found - marks end of cursor - so it's not an error _DBView_Error($mycurs,"fetch"); DBView_Close($mycurs); if ($retresult) return $result; else return count($result[ $colname[ 0 ] ]); } // }}} // {{{ DBView_Extract($source,$index_field,$values,$result = 0,$bind = 0) function DBView_Extract($source,$index_field,$values,$result = 0,$bind = 0) { // API compatibility: New code should use a referenced variable if ($result == 0) $retresult = true; else $retresult = false; $src = array(); $numrows = 0; if (is_string($source)) $numrows = DBView_Load($source,&$src,$bind); else if (is_array($source)) $src = $source; if ($numrows < 0) return $numrows; reset($src); $numcols = count(current($src)); if (is_array($values)) $crearr = true; else if (is_string($values)) if ($values == "*") $crearr = true; else $crearr = false; reset($src); $cnt = count(current($src)); if ($cnt == 0) return 0; else $result = array(); for ($inx = 0; $inx < $cnt; $inx++) { if ($index_field) $index = $src[ $index_field ][ $inx ]; else $index = $inx; if ($crearr) { $result[ $index ] = array(); if (is_array($values)) { $vcnt = count($values); for ($jnx = 0; $jnx < $vcnt; $jnx++) $result[ $index ][ $values[ $jnx ] ] = $src[ $values[ $jnx ] ][ $inx ]; } else { reset($src); while (list($allkey,$allvar) = each($src)) $result[ $index ][ $allkey ] = $src[ $allkey ][ $inx ]; } } else { $result[ $index ] = $src[ $values ][ $inx ]; } } if ($retresult) return $result; else return $cnt; } // }}} // {{{ DBView_Select($table,$select,$res,$where = false,$order = false,$indexfield = 0,$loginfo = "") function DBView_Select($table,$select,$res,$where = false,$order = false,$indexfield = 0,$loginfo = "") { if ($table == "") return -1; if (! is_array($select)) if ($select != "*") return -1; $viewstat = ""; // Ensure upper case if (is_array($select)) { reset($select); while (list($key,$value) = each($select)) $select[ $key ] = strtoupper($value); } // SELECT clause if (is_array($select)) { reset($select); $getfields = implode($select,","); } else $getfields = "*"; $sql = "select ".$getfields." from ".$table; // WHERE clause if ($where) { $sql .= " where "; $first = true; reset($where); while (list($wherename,$wherevalue) = each($where)) { if (! $first) $sql .= " and "; else $first = false; $sql .= $wherename."=:".$wherename; } } if ($order) $sql .= " order by " . $order; $result = DBView_Extract($sql,$indexfield,$select,&$res,&$where); return $result; } // }}} // {{{ DBView_Update($table,&$set,&$where,$loginfo = "") function DBView_Update($table,$set,$where,$loginfo = "") { if ($table == "") return -1; if (! is_array($set)) return -1; if (! is_array($where)) return -1; $sql = "UPDATE ".$table." SET "; $first = true; reset($set); while (list($setname,$setvalue) = each($set)) { if (! $first) $sql .= ","; else $first = false; $sql .= $setname."=:".$setname; } $sql .= " WHERE "; $first = true; reset($where); while (list($wherename,$wherevalue) = each($where)) { if (! $first) $sql .= " and "; else $first = false; $sql .= $wherename."=:".$wherename; } $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$set,"U",true); _DBView_Bind($mycurs,$where,"W",true); _DBView_Log("DBView_Update: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $rowcnt = ora_numrows($mycurs); DBView_Close($mycurs); return $rowcnt; } // }}} // {{{ DBView_Insert($table,&$fields,$returnid = false,$loginfo = "") function DBView_Insert($table,$fields,$returnid = false,$loginfo = "") { if ($table == "") return -1; if (! is_array($fields)) return -1; $idfield = false; $bindfields = array(); $nobindfields = array(); $info = ""; reset($fields); while (list($fieldname,$fieldvalue) = each($fields)) { $info .= "(".$fieldname."=>".$fieldvalue.")"; $p = explode("#", $fieldname); if (sizeof($p) == 1) $bindfields[ $fieldname ] = $fieldvalue; elseif ($p[ 1 ] == "nobind") $nobindfields[ $p[ 0 ] ] = $fieldvalue; elseif ($p[ 1 ] == "id") { $nobindfields[ $p[ 0 ] ] = "DC4SEQ.nextval"; global $$p[ 0 ]; $idfield = $p[ 0 ]; } else $bindfields[ $p[ 0 ] ] = $fieldvalue; } $allnames = array(); $allvals = array(); var_dump($allvals,$nobindfields); reset($nobindfields); while (list($fieldname,$fieldvalue) = each($nobindfields)) { $allnames[] = $fieldname; $allvals[] = $fieldvalue; } var_dump($allvals,$nobindfields); reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) { $allnames[] = $fieldname; $allvals[] = ":".$fieldname; } reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) global $$fieldname; $view = implode($allnames,","); $values = implode($allvals, ","); $sql = "insert into ".$table." (".$view.") values (".$values.")"; /* XXX RETURNING Not working yet if ($idfield) $sql .= " returning ".$idfield." into :returnid"; */ $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Log("DBView_Insert: <".$sql.">"); reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) { @ora_bind($mycurs,$fieldname,":".$fieldname,strlen($fieldvalue),1); $$fieldname = $fieldvalue; } /* XXX RETURNING Not working yet if ($idfield) { $db->bind("returnid",":returnid",12,2); } */ $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } DBView_Close($mycurs); return 0; } // }}} // {{{ DBView_Delete($table,&$where,$loginfo = "") function DBView_Delete($table,$where,$loginfo = "") { if ($table == "") return -1; if (! is_array($where)) return -1; $sql = "DELETE FROM ".$table." WHERE "; $first = true; reset($where); while (list($wherename,$wherevalue) = each($where)) { if (! $first) $sql .= " and "; else $first = false; $sql .= $wherename."=:".$wherename; } $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$where,"D",true); _DBView_Log("DBView_Delete: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $rowcnt = ora_numrows($mycurs); DBView_Close($mycurs); return $rowcnt; } // }}} // {{{ DBView_Execute($sql,$bindfields = 0,$loginfo = "") function DBView_Execute($sql,$bindfields = 0,$loginfo = "") { $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; $myvals = _DBView_Bind($mycurs,$bindfields,"E",false); _DBView_Log("DBView_Execute: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } /* get the data back from our globals */ if (is_array($myvals)) { reset($myvals); while (list($fname,$gname) = each($myvals)) { $bindfields[ $fname ] = $GLOBALS[ $gname ]; // _DBView_Log("_DBView_Bind out: <".$fname."><".$bindfields[ $fname ].">"); } } $rowcnt = ora_numrows($mycurs); DBView_Close($mycurs); return $rowcnt; } DBView_Insert("test",array("param1"=>"thies")); ?>
**** Purify instrumented ./php (pid 13313 at Tue Feb 1 17:18:24 2000) * Purify 4.5 Solaris 2, Copyright (C) 1992-1999 Rational Software Corp. All rights reserved. * For contact information type: "purify -help" * For TTY output, use the option "-windows=no" * Command-line: ./php ora.php * Options settings: -purify \ -purify-home=/dot/utility/pure/purify-4.5-solaris2 -threads=yes \ -use-internal-locks=yes -thread_stack_change=0x4000 -mt_safe_malloc=yes **** Purify instrumented ./php (pid 13313) **** FMR: Free memory read: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:218] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Reading 2 bytes from 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** FMW: Free memory write: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:218] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Writing 2 bytes to 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** FMR: Free memory read: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:219] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Reading 2 bytes from 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** FMR: Free memory read: * This is occurring while in: _zval_ptr_dtor [zend_execute_API.c:222] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * Reading 2 bytes from 0x38bd3a in the heap. * Address 0x38bd3a is 50 bytes into a freed block at 0x38bd08 of 60 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] execute [libphp4.a] execute [libphp4.a] php_execute_script [main.c:1206] main [cgi_main.c:518] * There have been 2 frees since this block was freed from: free [rtlib.o] _efree [zend_alloc.c:192] safe_free_zval_ptr [zend_execute_API.c:208] _zval_ptr_dtor [zend_execute_API.c:221] _zval_ptr_dtor_wrapper [zend_variables.c:180] zend_hash_clean [zend_hash.c:593] **** Purify instrumented ./php (pid 13313) **** ABR: Array bounds read: * This is occurring while in: shutdown_executor [zend_execute_API.c:137] zend_deactivate [zend.c:464] php_request_shutdown [main.c:733] main [cgi_main.c:542] _start [crt1.o] * Reading 2 bytes from 0x38d042 in the heap. * Address 0x38d042 is 135 bytes past end of a malloc'd block at 0x38cf60 of 92 bytes. * This block was allocated from: malloc [rtlib.o] _emalloc [zend_alloc.c:129] zend_hash_add_or_update [zend_hash.c:232] zend_fetch_var_address [libphp4.a] execute [libphp4.a] execute [libphp4.a] **** Purify instrumented ./php (pid 13313) **** Current file descriptors in use: 7 FIU: file descriptor 0: <stdin> FIU: file descriptor 1: <stdout> FIU: file descriptor 2: <stderr> FIU: file descriptor 3: "/etc/.name_service_door", O_RDONLY * File info: ?r--r--r-- 1 root root 0 Jul 30 1998 * This file descriptor was allocated from: _open64 [libc.so.1] _nsc_trydoorcall [libc.so.1] getpwuid_r [libc.so.1] snigun [sniq.c] nigconcbs [nigcon.c] osncon [nigcon.c] FIU: file descriptor 4: "/etc/mnttab", O_RDONLY * File info: srw-rw-rw- 0 root root 0 Feb 1 17:18 * This file descriptor was allocated from: _open [libc.so.1] _endopen [libc.so.1] fopen [libc.so.1] getdevinfo [getcwd.c] getcwd [libc.so.1] snlfncdir [snlfn.c] FIU: file descriptor 26: <reserved for Purify internal use> FIU: file descriptor 27: <reserved for Purify internal use> **** Purify instrumented ./php (pid 13313) **** Purify: Searching for all memory leaks... Memory leaked: 591 bytes (0.684%); potentially leaked: 0 bytes (0%) MLK: 380 bytes leaked in 5 blocks * This memory was allocated from: malloc [rtlib.o] zend_hash_add_or_update [zend_hash.c:242] zend_register_functions [zend_API.c:733] register_internal_class [zend_API.c:886] php_minit_oci [oci8.c:365] zend_startup_module [zend_API.c:677] * Block of 76 bytes (5 times); last block at 0x371518 MLK: 211 bytes leaked in 5 blocks * This memory was allocated from: malloc [rtlib.o] zend_hash_add_or_update [zend_hash.c:232] zend_register_functions [zend_API.c:733] register_internal_class [zend_API.c:886] php_minit_oci [oci8.c:365] zend_startup_module [zend_API.c:677] * Block of 47 bytes at 0x371130 * Block of 44 bytes at 0x371378 * Block of 40 bytes (3 times); last block at 0x371498 Purify Heap Analysis (combining suppressed and unsuppressed blocks) Blocks Bytes Leaked 10 591 Potentially Leaked 1 4104 In-Use 76 81656 ---------------------------------------- Total Allocated 87 86351 **** Purify instrumented ./php (pid 13313) **** Thread Summary : 1 threads in existence * Thread 0 [main thread] Stack: (0xeffff7b8 0xf0000000), size = 0x848 **** Purify instrumented ./php (pid 13313) **** * Program exited with status code 0. * 5 access errors, 5 total occurrences. * 591 bytes leaked. * 0 bytes potentially leaked. * Basic memory usage (including Purify overhead): 2939647 code 248476 data/bss 1056772 heap (peak use) 1848 stack * Shared library memory usage (including Purify overhead): 2196 solaris2_threads.so_pure_p3_c0_450_56 (shared code) 8556 solaris2_threads.so_pure_p3_c0_450_56 (private data) 8252504 libclntsh.so.1.0_pure_p3_c0_450_56 (shared code) 468880 libclntsh.so.1.0_pure_p3_c0_450_56 (private data) 140125 libm.so.1_pure_p3_c0_450_56 (shared code) 1332 libm.so.1_pure_p3_c0_450_56 (private data) 28919 libpam.so.1_pure_p3_c0_450_56 (shared code) 3172 libpam.so.1_pure_p3_c0_450_56 (private data) 2036 libdl.so.1_pure_p3_c0_450_56 (shared code) 4 libdl.so.1_pure_p3_c0_450_56 (private data) 82251 libresolv.so.2_pure_p3_c0_450_56 (shared code) 16296 libresolv.so.2_pure_p3_c0_450_56 (private data) 41730 libsocket.so.1_pure_p3_c0_450_56 (shared code) 3312 libsocket.so.1_pure_p3_c0_450_56 (private data) 733710 libnsl.so.1_pure_p3_c0_450_56 (shared code) 54408 libnsl.so.1_pure_p3_c0_450_56 (private data) 961297 libc.so.1_pure_p3_c0_450_56 (shared code) 30916 libc.so.1_pure_p3_c0_450_56 (private data) 11766 libinternal_stubs.so.1 (shared code) 832 libinternal_stubs.so.1 (private data) 35730 libaio.so.1_pure_p3_c0_450_56 (shared code) 6388 libaio.so.1_pure_p3_c0_450_56 (private data) 16272 libmp.so.2_pure_p3_c0_450_56 (shared code) 836 libmp.so.2_pure_p3_c0_450_56 (private data) <?php // -*- C++ -*- $GLOBALS[ "DBView_DB" ] = -1; $GLOBALS[ "DBView_Cursors" ] = array(); $GLOBALS[ "DBView_CurCnt" ] = 0; $GLOBALS[ "DBView_SawError" ] = false; $GLOBALS[ "DBView_Registered" ] = false; // }}} // {{{ _DBView_Log($what) function _DBView_Log($what) { $logfile = "/dot/logs/dbview.log"; clearstatcache(); if (! file_exists($logfile)) return; $fd = @fopen($logfile,"a"); if ($fd) { $what ="<" . getmypid() ." " . date("d.m.Y-H:i:s") . "> " . $what; fputs($fd,$what . "\n"); fclose($fd); } } // }}} // {{{ DBView_GetLogin(&$login) function DBView_GetLogin(&$login) { $login = array("user" =>"digicol", "password" =>"digicol", "service" =>"", "connect" =>"digicol/digicol"); // XXX maybe allow the "user" to specify the logint in dcinst?? /* if (isset($GLOBALS[ "DOCUMENT_ROOT" ])) { $filename = $GLOBALS[ "DOCUMENT_ROOT" ]."/include/sqllogin.htd"; $err = HTDL_Source($filename,&$htdlvars); if ($err == 0) if (is_array($htdlvars) && isset($htdlvars[ "sql" ])) { if (isset($htdlvars[ "sql" ][ "uid" ])) { $login[ "user" ] = $htdlvars[ "sql" ][ "uid" ]; $login[ "connect" ] = $login[ "user" ]; } if (isset($htdlvars[ "sql" ][ "pwd" ])) { $login[ "password" ] = $htdlvars[ "sql" ][ "pwd" ]; $login[ "connect" ] .= '/'.$login[ "password" ]; } if (isset($htdlvars[ "sql" ][ "service" ])) { if ($htdlvars[ "sql" ][ "service" ] != "*") { $login[ "service" ] = $htdlvars[ "sql" ][ "service" ]; $login[ "connect" ] .= '@'.$login[ "service" ]; } } } } */ return 0; } // }}} // {{{ _DBView_Error($mycurs,$func) function _DBView_Error($mycurs,$func) { _DBView_Log("Error: ".$func." - (".@ora_errorcode($mycurs).") <".@ora_error($mycurs).">"); $GLOBALS[ "DBView_SawError" ] = true; } // }}} // {{{ DBView_CloseDB() function DBView_CloseDB() { for ($inx = 0; $inx < $GLOBALS[ "DBView_CurCnt" ]; $inx++) @ora_close($GLOBALS[ "DBView_Cursors" ][ $inx ]); if ($GLOBALS[ "DBView_DB" ] != -1) @ora_logoff($GLOBALS[ "DBView_DB" ]); $GLOBALS[ "DBView_DB" ] = -1; } // }}} // {{{ DBView_GetDB() function DBView_GetDB() { if ($GLOBALS[ "DBView_DB" ] != -1) return $GLOBALS[ "DBView_DB" ]; $GLOBALS[ "DBView_Cursors" ] = array(); $GLOBALS[ "DBView_CurCnt" ] = 0; if (! $GLOBALS[ "DBView_Registered" ]) { register_shutdown_function("DBView_CloseDB"); $GLOBALS[ "DBView_Registered" ] = true; } DBView_GetLogin(&$login); $GLOBALS[ "DBView_DB" ] = @ora_logon($login[ "connect" ],""); if ($GLOBALS[ "DBView_DB" ] == false) { $GLOBALS[ "DBView_DB" ] = -1; _DBView_Log("DBView_GetDB: ora_logon failed"); return -1; } return $GLOBALS[ "DBView_DB" ]; } // }}} // {{{ DBView_Close($curs) function DBView_Close($curs) { if ($GLOBALS[ "DBView_SawError" ]) DBView_Ping(); if ($GLOBALS[ "DBView_DB" ] == -1) return -2; $GLOBALS[ "DBView_Cursors" ][ $GLOBALS[ "DBView_CurCnt" ] ] = $curs; $GLOBALS[ "DBView_CurCnt" ]++; $res = @ora_commit($GLOBALS[ "DBView_DB" ]); if ($res == false) { _DBView_Error($GLOBALS[ "DBView_DB" ],"commit"); return -1; } return 0; } // }}} // {{{ DBView_Ping() function DBView_Ping() { $db = DBView_GetDB(); if ($db == -1) { _DBView_Log("DBView_Ping: DBView_GetDB failed"); return -1; } $curs = @ora_open($db); if (! $curs) { _DBView_Log("DBView_Ping: ora_open failed"); DBView_CloseDB(); return -1; } $ok = @ora_parse($curs,"select sysdate from dual"); if (! $ok) { _DBView_Log("DBView_Ping: ora_parse failed"); @ora_close($curs); DBView_CloseDB(); return -2; } $ok = @ora_exec($curs); if (! $ok) { _DBView_Log("DBView_Ping: ora_exec failed"); @ora_close($curs); return -3; } @ora_close($curs); $GLOBALS[ "DBView_SawError" ] = false; _DBView_Log("DBView_Ping: success"); return 0; } // }}} // {{{ DBView_GetCursor() function DBView_GetCursor() { if ($GLOBALS[ "DBView_CurCnt" ] > 0) { $GLOBALS[ "DBView_CurCnt" ]--; $cur = $GLOBALS[ "DBView_Cursors" ][ $GLOBALS[ "DBView_CurCnt" ]]; return $cur; } $mydb = DBView_GetDB(); if ($mydb == -1) { return -1; $GLOBALS[ "DBView_SawError" ] = true; } $cur = @ora_open($mydb); if ($cur == false) { _DBView_Error($mydb,"open"); return -2; } return $cur; } // }}} // {{{ DBView_NextDC4Seq() function DBView_NextDC4Seq() { $tmp = array(); DBView_Extract("select DC4SEQ.nextval from DUAL",0,"NEXTVAL",&$tmp); return $tmp[ 0 ]; } // }}} // {{{ DBView_Fetch($mycurs,&$cols) function DBView_Fetch($mycurs,&$cols) { $res = @ora_fetch_into($mycurs,&$cols,ORA_FETCHINTO_NULLS | ORA_FETCHINTO_ASSOC); if ($res == false) { $code = ora_errorcode($mycurs); if ($code != 1403) // ORA-01403: no data found - marks end of cursor - so it's not an error _DBView_Error($mycurs,"fetch_into"); return -1 * $code; } return 0; } // }}} // {{{ DBView_Skip($mycurs,$rows) function DBView_Skip($mycurs,$rows) { _DBView_Log("DBView_Skip: ".$rows); while ($rows > 0) { $res = @ora_fetch($mycurs); if ($res == false) { _DBView_Error($mycurs,"fetch"); return -1; } $rows--; } return 0; } // }}} // {{{ _DBView_Bind($mycurs,&$bindfields,$marker,$forcein) function _DBView_Bind($mycurs,&$bindfields,$marker,$forcein) { $result = array(); if (is_array($bindfields)) { reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) { $p = explode("#", $fieldname); if (count($p) == 2) { $fname = $p[ 0 ]; $flag = $p[ 1 ]; } else { $fname = $fieldname; if ($forcein) $flag = "in"; else $flag = "inout"; } $globname = "__".$marker."__".$fname; // _DBView_Log("_DBView_Bind <".$fieldname."><".$flag."><".$fname.">=(".strlen($fieldvalue).")<".$fieldvalue.">"); switch ($flag) { case "in": if (strlen($fieldvalue) > 65000) _DBView_Log("DBView_Bind: value for <".$fname."> is larger 64K!"); $res = @ora_bind($mycurs,$globname,":".$fname,strlen($fieldvalue),ORA_BIND_IN); break; case "out": $res = @ora_bind($mycurs,$globname,":".$fname,65000,ORA_BIND_OUT); break; default: $res = @ora_bind($mycurs,$globname,":".$fname,65000,ORA_BIND_INOUT); break; } if ($res != true) _DBView_Error($mycurs,"bind"); $GLOBALS[ $globname ] = $fieldvalue; $result[ $fieldname ] = $globname; } } return $result; } // }}} // {{{ _DBView_Exec($mycurs) function _DBView_Exec($mycurs) { $res = @ora_exec($mycurs); if ($res == true) return 0; _DBView_Error($mycurs,"exec"); return -1 * ora_errorcode($mycurs); } // }}} // {{{ DBView_Parse($sql) function DBView_Parse(&$sql) { $mycurs = DBView_GetCursor(); if ($mycurs < 0) return $mycurs; $res = @ora_parse($mycurs,&$sql); if (! $res) { _DBView_Error($mycurs,"parse 1 <".$sql.">"); DBView_Close($mycurs); $mycurs = DBView_GetCursor(); if ($mycurs < 0) return $mycurs; $res = @ora_parse($mycurs,&$sql); if (! $res) { _DBView_Error($mycurs,"parse 2 <".$sql.">"); return -1 * ora_errorcode($mycurs); } } return $mycurs; } // }}} // {{{ DBView_Open($sql,&$numcols,$bindfields = 0) function DBView_Open($sql,&$numcols,$bindfields = 0) { $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$bindfields,"O",true); _DBView_Log("DBView_Open: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $numcols = @ora_numcols($mycurs); return $mycurs; } // }}} // {{{ DBView_Load($sql,$result = 0,$bindfields = 0) function DBView_Load($sql,$result = 0,$bindfields = 0) { // API compatibility: New code should use a referenced variable if ($result == 0) $retresult = true; else $retresult = false; $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$bindfields,"L",true); _DBView_Log("DBView_Load: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $numcol = @ora_numcols($mycurs); $result = array(); $colnames = array(); for ($inx = 0; $inx < $numcol; $inx++) { $colname[ $inx ] = @ora_columnname($mycurs,$inx); $result[ $colname[ $inx ] ] = array(); } while (@ora_fetch($mycurs)) for ($inx = 0; $inx < $numcol; $inx++) $result[ $colname[ $inx ] ][ ] = @ora_getcolumn($mycurs,$inx); $code = @ora_errorcode($mycurs); if ($code != 1403) // ORA-01403: no data found - marks end of cursor - so it's not an error _DBView_Error($mycurs,"fetch"); DBView_Close($mycurs); if ($retresult) return $result; else return count($result[ $colname[ 0 ] ]); } // }}} // {{{ DBView_Extract($source,$index_field,$values,$result = 0,$bind = 0) function DBView_Extract($source,$index_field,$values,$result = 0,$bind = 0) { // API compatibility: New code should use a referenced variable if ($result == 0) $retresult = true; else $retresult = false; $src = array(); $numrows = 0; if (is_string($source)) $numrows = DBView_Load($source,&$src,$bind); else if (is_array($source)) $src = $source; if ($numrows < 0) return $numrows; reset($src); $numcols = count(current($src)); if (is_array($values)) $crearr = true; else if (is_string($values)) if ($values == "*") $crearr = true; else $crearr = false; reset($src); $cnt = count(current($src)); if ($cnt == 0) return 0; else $result = array(); for ($inx = 0; $inx < $cnt; $inx++) { if ($index_field) $index = $src[ $index_field ][ $inx ]; else $index = $inx; if ($crearr) { $result[ $index ] = array(); if (is_array($values)) { $vcnt = count($values); for ($jnx = 0; $jnx < $vcnt; $jnx++) $result[ $index ][ $values[ $jnx ] ] = $src[ $values[ $jnx ] ][ $inx ]; } else { reset($src); while (list($allkey,$allvar) = each($src)) $result[ $index ][ $allkey ] = $src[ $allkey ][ $inx ]; } } else { $result[ $index ] = $src[ $values ][ $inx ]; } } if ($retresult) return $result; else return $cnt; } // }}} // {{{ DBView_Select($table,$select,$res,$where = false,$order = false,$indexfield = 0,$loginfo = "") function DBView_Select($table,$select,$res,$where = false,$order = false,$indexfield = 0,$loginfo = "") { if ($table == "") return -1; if (! is_array($select)) if ($select != "*") return -1; $viewstat = ""; // Ensure upper case if (is_array($select)) { reset($select); while (list($key,$value) = each($select)) $select[ $key ] = strtoupper($value); } // SELECT clause if (is_array($select)) { reset($select); $getfields = implode($select,","); } else $getfields = "*"; $sql = "select ".$getfields." from ".$table; // WHERE clause if ($where) { $sql .= " where "; $first = true; reset($where); while (list($wherename,$wherevalue) = each($where)) { if (! $first) $sql .= " and "; else $first = false; $sql .= $wherename."=:".$wherename; } } if ($order) $sql .= " order by " . $order; $result = DBView_Extract($sql,$indexfield,$select,&$res,&$where); return $result; } // }}} // {{{ DBView_Update($table,&$set,&$where,$loginfo = "") function DBView_Update($table,$set,$where,$loginfo = "") { if ($table == "") return -1; if (! is_array($set)) return -1; if (! is_array($where)) return -1; $sql = "UPDATE ".$table." SET "; $first = true; reset($set); while (list($setname,$setvalue) = each($set)) { if (! $first) $sql .= ","; else $first = false; $sql .= $setname."=:".$setname; } $sql .= " WHERE "; $first = true; reset($where); while (list($wherename,$wherevalue) = each($where)) { if (! $first) $sql .= " and "; else $first = false; $sql .= $wherename."=:".$wherename; } $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$set,"U",true); _DBView_Bind($mycurs,$where,"W",true); _DBView_Log("DBView_Update: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $rowcnt = ora_numrows($mycurs); DBView_Close($mycurs); return $rowcnt; } // }}} // {{{ DBView_Insert($table,&$fields,$returnid = false,$loginfo = "") function DBView_Insert($table,$fields,$returnid = false,$loginfo = "") { if ($table == "") return -1; if (! is_array($fields)) return -1; $idfield = false; $bindfields = array(); $nobindfields = array(); $info = ""; reset($fields); while (list($fieldname,$fieldvalue) = each($fields)) { $info .= "(".$fieldname."=>".$fieldvalue.")"; $p = explode("#", $fieldname); if (sizeof($p) == 1) $bindfields[ $fieldname ] = $fieldvalue; elseif ($p[ 1 ] == "nobind") $nobindfields[ $p[ 0 ] ] = $fieldvalue; elseif ($p[ 1 ] == "id") { $nobindfields[ $p[ 0 ] ] = "DC4SEQ.nextval"; global $$p[ 0 ]; $idfield = $p[ 0 ]; } else $bindfields[ $p[ 0 ] ] = $fieldvalue; } $allnames = array(); $allvals = array(); var_dump($allvals,$nobindfields); reset($nobindfields); while (list($fieldname,$fieldvalue) = each($nobindfields)) { $allnames[] = $fieldname; $allvals[] = $fieldvalue; } var_dump($allvals,$nobindfields); reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) { $allnames[] = $fieldname; $allvals[] = ":".$fieldname; } reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) global $$fieldname; $view = implode($allnames,","); $values = implode($allvals, ","); $sql = "insert into ".$table." (".$view.") values (".$values.")"; /* XXX RETURNING Not working yet if ($idfield) $sql .= " returning ".$idfield." into :returnid"; */ $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Log("DBView_Insert: <".$sql.">"); reset($bindfields); while (list($fieldname,$fieldvalue) = each($bindfields)) { @ora_bind($mycurs,$fieldname,":".$fieldname,strlen($fieldvalue),1); $$fieldname = $fieldvalue; } /* XXX RETURNING Not working yet if ($idfield) { $db->bind("returnid",":returnid",12,2); } */ $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } DBView_Close($mycurs); return 0; } // }}} // {{{ DBView_Delete($table,&$where,$loginfo = "") function DBView_Delete($table,$where,$loginfo = "") { if ($table == "") return -1; if (! is_array($where)) return -1; $sql = "DELETE FROM ".$table." WHERE "; $first = true; reset($where); while (list($wherename,$wherevalue) = each($where)) { if (! $first) $sql .= " and "; else $first = false; $sql .= $wherename."=:".$wherename; } $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; _DBView_Bind($mycurs,$where,"D",true); _DBView_Log("DBView_Delete: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } $rowcnt = ora_numrows($mycurs); DBView_Close($mycurs); return $rowcnt; } // }}} // {{{ DBView_Execute($sql,$bindfields = 0,$loginfo = "") function DBView_Execute($sql,$bindfields = 0,$loginfo = "") { $mycurs = DBView_Parse($sql); if ($mycurs < 0) return $mycurs; $myvals = _DBView_Bind($mycurs,$bindfields,"E",false); _DBView_Log("DBView_Execute: <".$sql.">"); $res = _DBView_Exec($mycurs); if ($res != 0) { DBView_Close($mycurs); return $res; } /* get the data back from our globals */ if (is_array($myvals)) { reset($myvals); while (list($fname,$gname) = each($myvals)) { $bindfields[ $fname ] = $GLOBALS[ $gname ]; // _DBView_Log("_DBView_Bind out: <".$fname."><".$bindfields[ $fname ].">"); } } $rowcnt = ora_numrows($mycurs); DBView_Close($mycurs); return $rowcnt; } DBView_Insert("test",array("param1"=>"thies")); ?>