pdo writes garbled characters when the content written to the database is in Chinese
A快递员***
A快递员*** 2021-11-02 00:50:30
0
3
810

$_POST['phone'], 'pwd' => md5($_POST['pwd' ]), 'add_time' => time(), 'nickname' => isset($_POST['nickname']) ? $_POST['nickname'] : $_POST['phone'], 'sex' = > isset($_POST['avatar']) ? $_POST['sex'] : 0, 'avatar' => isset($_POST['avatar']) ? $_POST['avatar'] : '' ); $add = insert('php_user',$arr); return_json(0,'Registration successful'); function connect(){ $db = array( 'charset' => 'utf8', 'port' => 3306, ; 'hao1' ); $dsn = "{$db['type']}:host={$db['host']}; dbname={$db['name']}; charset={$db[ 'charset']}; port={$db['port']}" try { //Instantiate the PDO class and create the PDO object $pdo = new PDO($dsn,$db['user'],$db[ 'pass']); } catch (PDOException $e) { die('Database error:'.$e->getMessage()); } return $pdo;}function insert($table,$data=[]) { //Connect pdo $pdo = connect(); //Create SQL statement $sql = "INSERT INTO {$table} SET "; //Assemble insert statement if(is_array($data)){ foreach ($data as $ k = & gt; $ v) {$ SQL. = $ k. '= "'. $ v. '",';}} else {reTurn false;} // Remove the tail comma and add a segment number to end $ SQL = rtrim(trim($sql),',').';'; //Create PDO preprocessing object $stmt = $pdo->prepare($sql); //Perform new operations if($stmt-> ;execute()){ if($stmt->rowCount()>0){ return true;else { return false; }}

A快递员***
A快递员***

reply all (1)
逆旅行人

Look at the encoding method of your database and the encoding method in your php

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!