0

I'm working on a symfony2 project. when i insert data with french accents like (é), it is inserted as shown in this image: enter image description here

when i try to retrieve this data using a php file to use it in android app, i use this code:

<?php
    define('HOST','localhost');
    define('USER','root');
    define('PASS','');
    define('DB','adproject');
    $con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect to db');
$sql = "select * from actualite";

$result = array();

    $res = mysqli_query($con,$sql);

    while($row = mysqli_fetch_array($res)){

    array_push($result,
    array('id'=>$row[0],
    'login'=>$row[1],
    'password'=>$row[2]
    ));

    }
echo json_encode($result); 


mysqli_close($con);
?>

I get nothing because of the accents in the database. Any suggestion?

1
  • You shouldn't be using the old deprecated mysqli_ function calls! Just to let you know, it's not a good idea. Commented Mar 21, 2017 at 16:44

1 Answer 1

2

I suspect you'll need to go through this Configuring the Database section and setting up for UTF8:

http://symfony.com/doc/current/doctrine.html#configuring-the-database

Let us know if you've already done that.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the reply. Where can i find the my.cnf file?
It might not be called my.cnf file. I'm using CentOS, and the file to change is server.cnf located in the path /etc/my.cnf.d. Which Linux distro are you using, or are you on Windows?
I made the configuration , now the (é) is saved in database as © and retrieved as "\u00a9", how can i show it again as (é)?
You might have to clean out your database. Try deleting those rows manually. It might be a good idea to delete the database and run php bin/console doctrine:database:create, and then retry your code.
I think this is how json_encode is supposed to show the data, so my probleme is solved ;)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.