我想在表格中插入一个值。但是当我在代码下面运行时,我看到用????
显示了这个值。我该如何解决这个问题?
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();
}
?>
提前感谢您的帮助。
答案 0 :(得分:0)
TRy:PDO("mysql:host=localhost;dbname=DB;charset=UTF8");
这是一个有帮助的解决方案:
$pdo->query("SET CHARACTER_SET_RESULTS=NULL");<br>
$result = $pdo->query("select * from table");
答案 1 :(得分:0)
我认为数据库名称没有反映在您的代码中。您可以尝试更改下面的代码,
$dbname = "my_db";
$dsn = "mysql:host=localhost;dbname="+$dbname+";
或
$dsn = "mysql:host=localhost;dbname=my_db;