2


here is my problem, i have an arabic database mysqli UTF8_general_ci and the charset of my php file is UTF-8 when i seled data i get "?????????????".
on php my admin i can write and read with no problem, also on php i can, but the problem is when is when i get data from the database! here is my code:

<meta charset="UTF-8"/>

$connexion = new mysqli(HOST_DB,USER_DB,MDP_DB,DB_NAME);
        if ($connexion->error) {
            die('Une erreur s\'est produite :' .$connexion->error);
        }
        else{
            $sql = "SELECT nom, description, date, formateur, image, prix, lieux FROM news";
            if ($result = mysqli_query($connexion,$sql)) {
                while ($ligne = mysqli_fetch_assoc($result)) {
                    echo'
                        <ul>
                            <li><figure>
                                <figcaption>
                                    <h1>'.$ligne["nom"].'</h1>
                                    <p>'.$ligne["description"].'</p>
                                    <strong>اليوم:'.$ligne["date"].'</strong><br/>
                                    <strong>المكان:'.$ligne["lieux"].'</strong><br/>
                                    <strong>المدرس:'.$ligne["formateur"].'</strong><br/>
                                    <strong>الثمن: '.$ligne["prix"].'دينار</strong>
                                    </figcaption>
                                <img src="Images/'.$ligne["image"].'" height="250px" width="250px">
                            </figure></li>
                        </ul>
                    ';
                }
            }
        }
RaisoMos
  • 159
  • 4
  • 11
  • This looks like an error that you could see when the charset is not set for the mysql connection. Try to set it for the connection. – useSticks Feb 06 '14 at 13:44
  • Just add this code just before your select query: mysql_query("set characer set utf8"); – Sathish D Feb 06 '14 at 13:45
  • Did you create your database using UTF-8 encoding too? `CREATE DATABASE db DEFAULT CHARACTER SET utf8` – Alejandro Iván Feb 06 '14 at 13:45
  • yes when i created the batabase the encoding is utf8_general_ci, and i added mysql_query("set characer set utf8"); but still the problem :( – RaisoMos Feb 06 '14 at 13:49
  • Probably your browser is acting up, did you try to change character encoding to UTF-8 in the browser ? – Mostafa Berg Feb 06 '14 at 13:52
  • This seems to be a recurring theme, see if my answer to this question covers it: http://stackoverflow.com/questions/8473965/there-are-symbols-like-and-so-on-in-database-what-to-do/8474356#8474356 – CD001 Feb 06 '14 at 13:55
  • i use chrome, i changed firefox, IE, and Opera, the same problem, i used xampp and i changed wamp server, and the same problem :( – RaisoMos Feb 06 '14 at 13:56

6 Answers6

5

put this code after the connection to mysql. mysqli_set_charset($connexion,'utf8'); this is final code for connection to database: $connexion = new mysqli(HOST_DB,USER_DB,MDP_DB,DB_NAME); mysqli_set_charset($connexion,'utf8');

Pedram
  • 51
  • 1
1

it will work you have to change my.ini file inside mysql\bin and add the below line

character-set-server = utf8

0
<?php header('Content-Type: text/html; charset=utf-8'); ?>

will modify the header to your encoding

JohnTaa
  • 2,722
  • 2
  • 15
  • 15
0

Run this SQL query:

SET NAMES 'utf-8'
Mohammad
  • 572
  • 5
  • 4
0

The problem is from XAMPP, i swiched to Wamp server and rebooted the machine and all work fine,
Thanks ALL

RaisoMos
  • 159
  • 4
  • 11
-2

Please check your PHP version using PHP Version Manager. You should upgrade PHP to 7.1.33 or later to solve this problem, otherwise the above solutions do not help much.

Alaa Sadik
  • 1,029
  • 12
  • 19