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>';
6
  • 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. Apr 11, 2021 at 18:59
  • 1
    DO NOT USE insert query like that. You are opened to sql injections. Use parameters
    – Giacomo M
    Apr 11, 2021 at 19:01
  • 1
    Why (SELECT sysdate FROM dual)? Simply use sysdate Apr 11, 2021 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, 2021 at 19:52
  • 1
    (1) Pass the values as bind variables, (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, 2021 at 20:46

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.