0
votes

I have an application which saves html templates as a clob in an oracle DB.
When I update previously saved HTML the   becomes ??.

$sql = "UPDATE headers 
        SET header_code = :HEADER_CODE
        WHERE header_ID = :HEADER_ID ";
...

oci_bind_by_name($stid, ':HEADER_CODE', $form_qs['HEADER_CODE']); 
oci_bind_by_name($stid, ':HEADER_ID', $form_qs['HEADER_ID']); 
...

oracle version info:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
"CORE 10.2.0.4.0 Production"
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

PHP Version 5.2.6

2
Are entities being decoded at any point in your code? non-breaking spaces use a different character code than regular spaces. - datasage
No I'm not, What to you suggest? - Aba
The nbsp entity is getting converted to the actual unicode character somewhere. I don't think oracle or the prepared statements would do that. - datasage
Again, it's only happening on the update not on the original save so the code is the same. The information in the text area though is different when I first entered the information the HTML entity is shown as typed   when I go back to make the update it is displayed as a blank space. I hope this helps. - Aba
In that case, are you sure the string still has   before you do the update query? An   might be converted in an edit form if you are not encoding entities at that point. - datasage

2 Answers

1
votes

OK after datasage got me to realize this is an encoding issue and not a database issue I refocused my google searching and found it's the textbox (along with my enctype) which is converting the   into a 2 character Unicode (I echoed out strlen($form_qs['HEADER_CODE'])).

That being said I'm now replacing the & with & so the textbox will display   not a blank space. I hope the solution will not mess other things up but time will tell.

str_replace('&','&',$form_qs['HEADER_CODE']);

(Thanks DoSparKot and nickb for the formatting help)

0
votes

I'm not sure about syntax errors in your code, however you can use oci_new_descriptor() to open a new descriptor for CLOB

<?php
$clob = oci_new_descriptor ($conn, OCI_D_LOB);
oci_bind_by_name ($stid, ':HEADER_CODE', $clob, -1, OCI_B_CLOB);
$clob->write  ($form_qs['HEADER_CODE']);

oci_bind_by_name($stid, ':HEADER_ID', $form_qs['HEADER_ID']);

//after execution/commit
$clob->free();
?>

OCI_D_LOB: Data of LOB type

OCI_B_CLOB: Binding of CLOB type