配置PHP文件
define("DB_SERVER", 'localhost');
define("DB_USER", 'root');
define("DB_PASS", 'pass');
define("DB_NAME", 'db');
define("mysql_query", 'SET CHARACTER_SET utf8');
这里是表结构,因为表被设置为utf8_persian_ci,当我从phpmyadmin插入数据时,它工作得很好,阿拉伯语文本得到插入。
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(111) | NO | PRI | NULL | auto_increment |
| name | varchar(122) | NO | | NULL | |
+-------+--------------+------+-----+---------+----------------+
查询函数有点像下面。
////quering
public function query($sql){
$this->last_query = $sql;
$result = mysql_query($sql, $this->connection);
$this->confirm_query($result);
return $result;
}
,但在这里,当我从数据库中获取数据,我得到(?????)类型的文本。如果插入从php输入,当我检查数据库(Ø´UœØ¨Ø´Ø¨Ø´Ø¨Ø´Ø¨Ø´Ø¨Ø´)类型的数据,但当我从php它听到回声显示正确的,但在数据库的格式已经改变了。
1-如果从phpmyadmin数据插入到数据库工作正常(意味着数据库字符是ok的),但可以回显PHP (?????)
2- if insert by PHP from…在数据库(Ø´UœØ¨Ø´Ø¨Ø´Ø¨Ø´Ø¨Ø´Ø¨Ø´)但在回声好
如何设置插入表单插入阿拉伯语文本作为数据库(mysql)
我怎么能回它作为数据格式是在数据库?
我们必须在connection.php中设置utf8,为所有人提供数据库连接:
<?php
class Database {
protected $host='localhost';
protected $user='root';
protected $db = 'db_test';
protected $pass = '';
protected $conn;
public function __construct(){
$this->conn = new PDO("mysql:host=".$this->host.";dbname=".$this->db,$this->user,$this->pass);
$this->conn->exec("SET CHARACTER SET utf8");
}
}