mysql을 사용하고 있습니다. 인스턴트 메신저를 할 때 SELECT * FROM table
РђР»РμРєСЃРμРμРІРёС ‡를 반환합니다. 그것은 러시아 문자를 표시해야합니다. 내 데이터베이스, 테이블, 열은 utf8_general_ci로 설정됩니다. php 파일은 bom이없는 utf8입니다. 내가 쿼리 집합 이름이 cp1251, 그것은 문제를 해결하지만 왜 모든 것들이 UTF 8에 있다면 cp1251가 무엇입니까?mysql의 문자 세트가 잘못되었습니다.
데이터베이스 연결
class Database {
public $user = 'root';
public $password = '';
function __construct() {
$this->connect();
}
function connect() {
try {
$this->dbh = new PDO('mysql:host=localhost;dbname=university;charset=utf8', $this->user, $this->password);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
function selectQuery($sql) {
$this->stmt = $this->dbh->prepare($sql);
$this->stmt->execute();
}
function insertQuery($sql) {
$this->stmt = $this->dbh->prepare($sql);
$this->stmt->execute();
}
}
쿼리이 쿼리 설정 데이터 정렬 설명서 연결 후
$this->db = new Database();
$q = $this->db->selectQuery('SELECT * FROM students');
$data = $this->db->stmt->fetchAll($q);
마지막 질문 이후에 PDO로 변경되었습니다. – SamV
-1 두 번 같은 질문을했습니다. –