2

I want to insert a value in a table . But when I am running below code , I see that shows this value with ???? . How can I solve this problem ?

insert.php

<?php
    include "connect.php";
    $query = "INSERT INTO customer_tab (name,phone,address) VALUE ('آزاده','0981245','ایران کرمان')";
    $result = $connect->prepare($query);
    $result->execute();
?>

connect.php

<?php
    $server = "localhost";
    $user = "azadgh";
    $pass = "*******";
    $dbname = "my_db";
    $dsn = "mysql:host=localhost;dbname=$dbname";
    try {
        $connect = new PDO($dsn, $user, $pass);
        $connect->exec("SET character_set_connection = 'UTF8");
        $connect->exec("SET NAMES 'UTF8");
        $connect->exec("SET CHARACTER SET 'utf8'");
    } catch (PDOException $error) {
        echo "unable to connect : " . $error->getMessage();
    }
?>

Thanks in advance for any help.

Aftab H.
  • 1,517
  • 4
  • 13
  • 25
Azade
  • 359
  • 2
  • 15

2 Answers2

0

TRy: PDO("mysql:host=localhost;dbname=DB;charset=UTF8");
Here is one solution that helped:
$pdo->query("SET CHARACTER_SET_RESULTS=NULL");<br> $result = $pdo->query("select * from table");

halojoy
  • 225
  • 2
  • 7
0

I think database name is not reflecting in your code. Can you try to change your code like below,

$dbname = "my_db";
$dsn = "mysql:host=localhost;dbname="+$dbname+";

or

$dsn = "mysql:host=localhost;dbname=my_db;