1

excuse me...! my english is not very good! until last week i'm use "www.000webhost.com" webhost and i had no problem!!! But today I bought a new server and use old file like before... I dont know the problem is from php files or database?

Please show me the solution

this my php code

    <?php 
    //Creating a connection
    $con = mysqli_connect("___","___","___","___");

    if (mysqli_connect_errno())
    {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    /*Get the id of the last visible item in the RecyclerView from the request and store it in a variable. For            the first request id will be zero.*/  
    $id = $_GET["id"];

    $sql= "Select * from db_app where id between ($id+1) and ($id+10)";

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

    while ($row = mysqli_fetch_assoc($result)) {

        $array[] = $row;

    }
    header('Content-Type:Application/json');

    echo json_encode($array);

    mysqli_free_result($result);

    mysqli_close($con);

 ?>

this my database code

    CREATE DATABASE `android_db`;

USE `android_db`;


CREATE TABLE IF NOT EXISTS `db_app` (
  `id` int(15) NOT NULL AUTO_INCREMENT,
  `movie_name` varchar(45) NOT NULL,
  `movie_image` varchar(10000) NOT NULL,
  `movie_genre` varchar(40) NOT NULL,
  PRIMARY KEY (`id`)
);
  • Go through this entire post https://stackoverflow.com/questions/279170/utf-8-all-the-way-through your answers are most likely in there. – Funk Forty Niner Jul 22 '17 at 15:41
  • Also go through [ask] while you're at it. – cs95 Jul 22 '17 at 15:43
  • Use `utf8mb4` for the database column and set the char-set of the connection as @Ray Hong said in the answer. *Note, if you stored a Unicode text to a non-Unicode column, MySQL is going to change the characters to `?` and you will lose the characters for ever. no matter what you did* – Accountant م Jul 22 '17 at 15:53
  • @Accountant_م i get this error Fatal error: Call to a member function set_charset() on null – Farshad Asgharzadeh Jul 22 '17 at 16:03
  • @FarshadAsgharzadeh that is because the object `$mysqli` is not created. you have to first create the object `$mysqli = new mysqli("example.com", "your_user_name", "your_password", "your_database_name");` in your code the object is called `$con` replace `$mysqli` with `$con` – Accountant م Jul 22 '17 at 16:12
  • @Accountant_م thank you , now show me this "\u0641\u0631\u0634\u0627\u062f" instead persian character like "فرشاد" – Farshad Asgharzadeh Jul 22 '17 at 16:35
  • @FarshadAsgharzadeh You are echoing the JSON. Use `json_encode( $text, JSON_UNESCAPED_UNICODE );` see this question ([https://stackoverflow.com/questions/16498286/why-does-the-php-json-encode-function-convert-utf-8-strings-to-hexadecimal-entit](https://stackoverflow.com/questions/16498286/why-does-the-php-json-encode-function-convert-utf-8-strings-to-hexadecimal-entit)) – Accountant م Jul 22 '17 at 16:38
  • @Accountant_م I do not know how to thank you, you gave me a great favor, finally I got comfortable tonight. :) – Farshad Asgharzadeh Jul 22 '17 at 16:49
  • @FarshadAsgharzadeh you are welcome :) – Accountant م Jul 22 '17 at 16:57

1 Answers1

3

This happens when the character set is not set.

Try after the mysql connection,

/* change character set to utf8 */
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);
    exit();
} else {
    printf("Current character set: %s\n", $mysqli->character_set_name());
}

Taken from: http://php.net/manual/en/mysqli.set-charset.php

Jisu Hong
  • 724
  • 1
  • 7
  • 22