$_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; }}
Look at the encoding method of your database and the encoding method in your php