0

I want to store special characters in oracle sql, like á, é, ő etc. How can i do it? Every character turns into ?? when i select them. Never used oracle sql its a real pain in the ass for me.

PHP code:

$id = $_POST['id'];
$comment = $_POST['comment-content'];
$username = $_SESSION['username'];

$q = "INSERT INTO hozzaszolasok (username, image_id, content, date_added) VALUES ('$username',$id,'$comment',(SELECT sysdate FROM dual))";
$s = oci_parse($c, $q);
oci_execute($s);

oci_free_statement($s);
oci_close($c);

echo '<script>window.location.href = "comments.php?id=' . $id . '";</script>';
Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
TimSom
  • 11
  • 1
  • 3
    Probably need to set the character set on the connection `$c`. You look to be open to SQL injections with this code. Variables/user input should not be in SQL. – user3783243 Apr 11 '21 at 18:59
  • 1
    DO NOT USE insert query like that. You are opened to sql injections. Use parameters – Giacomo M Apr 11 '21 at 19:01
  • 1
    Why `(SELECT sysdate FROM dual)`? Simply use `sysdate` – Wernfried Domscheit Apr 11 '21 at 19:12
  • 1
    Characters getting turned into ?? or something is likely a difference in character set between your client and your database. Check the database character set to see if it supports multibyte characters. AL32UTF8 is one such charset. – eaolson Apr 11 '21 at 19:52
  • What is the database character set? What is your `NLS_LANG` value? How did you set the HTML charset? – Wernfried Domscheit Apr 11 '21 at 20:41
  • 1
    (1) [Pass the values as bind variables](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1), (2) Check that the database is actually not storing them correctly and it isn't just that they are stored correctly but when you look the user interface is not displaying them correctly; (3) If you've done 1 and 2 and it still is not working then try using the `NVARCHAR2` data type instead of `VARCHAR2`. – MT0 Apr 11 '21 at 20:46

1 Answers1

0

When you open the connection to Oracle DB, specify the character set parameter as AL32UTF8, see the oci_connect() documentation:

$c = oci_connect($username, $password, $connection_string, 'AL32UTF8');

Some of the older globalization information in The Underground PHP and Oracle Manual may still be relevant.

Review the globalization recommendations for your PHP version to make sure your HTML pages are sending characters to the browser correctly.

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48