0

i have dig very deep in this and view a lot of questions and that's not working every time i try to insert arabic it's showing like this (?????)

Database Connection

$db = new PDO( 
    'mysql:host=localhost;dbname=addme', 
    'root', 
    'a', 
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);

Inserting Page

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php

include("config.php");

$name = $_POST['name'];
$about = $_POST['about'];
$category = $_POST['category'];

$theId = "";
$date = round(microtime(true) * 1000);


$stmt = $db->prepare("INSERT INTO users(id,username,about,date,category) VALUES(
    :field1,
    :field2,
    :field3,
    :field4,
    :field5)
");
$stmt->execute(
    array(':field1' => $theId, 
        ':field2' => $name, 
        ':field3' => $about, 
        ':field4' => $date,
        ':field5' => $category));
$affected_rows = $stmt->rowCount();

        $response["success"] = 1;
        $response["message"] = "Added You.";

        // echoing JSON response
        echo json_encode($response);

Database Encoding

utf8_general_ci

The values from android app posting it. The arabic post was working very fine using MySQL connection and after decide to use PDO this problem show up.

1 Answers1

1

replace this part of code with yours I haven't tested but should work

$db = new PDO( 
    'mysql:host=localhost;dbname=addme;charset=utf8', 
    'root', 
    'a')
);

enter image description here

ARIF MAHMUD RANA
  • 5,026
  • 3
  • 31
  • 58