php4, Oracle OCI8, and character arrays..

From: Date: Thu, 02 Dec 1999 21:41:24 +0000
Subject: php4, Oracle OCI8, and character arrays..
Groups: php.version4 
Request: Send a blank email to php-version4+get-7277@lists.php.net to get a copy of this message
Is anyone using php4's OCI8 interface to access VARCHAR2 and CHAR datatypes from an Oracle 8.0.5 database? I have no problem retrieving numeric and date types from the database, but VARCHAR2 fields always consist of '\0' when I retrieve them from the database using, for example, the OCIFetchStatement function. Without rhyme or reason, though, some VARCHAR fields result in strings that are the original database value, with every character preceded by '\0'. Has anyone solved this or a similar problem? I'd imagine that there is some sort of multibyte/wide character option that I am missing, but I didn't see anything obvious to fiddle with in oci8.c. Could you point me the right direction? scott ----------------------------------- My table: CREATE TABLE boxes ( ip VARCHAR(16), name VARCHAR(64), test INTEGER ); INSERT INTO boxes VALUES ('127.0.0.1', 'localhost', '123'); INSERT INTO boxes VALUES ('192.168.0.1', 'me', '456'); COMMIT; ----------------------------------------- My script (almost straight out of the annotated manual): <?php /* OCIFetchStatement example mbritton@verinet.com (990624) */ $conn = OCILogon("scott","tiger", "wguo2"); $stmt = OCIParse($conn,"select * from boxes"); OCIExecute($stmt); $nrows = OCIFetchStatement($stmt,$results); if ( $nrows > 0 ) { print "<TABLE BORDER=\"1\">\n"; print "<TR>\n"; while ( list( $key, $val ) = each( $results ) ) { print "<TH>$key</TH>\n"; } print "</TR>\n"; for ( $i = 0; $i < $nrows; $i++ ) { reset($results); print "<TR>\n"; while ( $column = each($results) ) { $data = $column['value']; print "<TD>$data[$i]</TD>\n"; } print "</TR>\n"; } print "</TABLE>\n"; } else { echo "No data found<BR>\n"; } print "$nrows Records Selected<BR>\n"; OCIFreeStatement($stmt); OCILogoff($conn); ?> ----------------------------------------- My results in the webbrowser: IP NAME TEST 123 456 2 Records Selected -------------------------------------------- This is the actual source of the webpage (^@ is '\0'. Note the occasional prescence of the data mixed in with the NULL's): <TABLE BORDER="1"> <TR> <TH>IP</TH> <TH>NAME</TH> <TH>TEST</TH> </TR> <TR> <TD>^@</TD> <TD>^@l^@o^@c^@a^@l^@h^@o^@s^@t</TD> <TD>123</TD> </TR> <TR> <TD>^@1^@9^@2^@.^@1^@6^@8^@.</TD> <TD>^@m^@e</TD> <TD>456</TD> </TR> </TABLE> 2 Records Selected<BR> -- ------------------------------------------------------------------- scott jacobs foveon corporation -------------------------------------------------------------------

« previous php.version4 (#7277) next »