<?php header ( "Content-type: text/html; charset=utf-8" ); if ($con = mysql_connect ( 'localhost', 'root', '' )) { echo 'Connectting Database is successful! <br/>'; } else { echo 'Connectting Database is false! <br/>'; } if (mysql_select_db ( phpprac )) { echo 'Selection is successful! <br/>'; } else { 'Selection is false! <br/>'; } // mysql_query ( 'set names utf8' ); // if(mysql_query("insert into test(name) values('荔枝')")) // { // print_r("插入成功"); // } // else { // print_r("插入失败"); // } $query = mysql_query ( 'select * from test' ); while ( $row = mysql_fetch_row ( $query ) ) { echo $row [1] . $row [0] . '个<br/>'; } echo '显示成功'; mysql_close ( $con );
PHP displays some garbled characters? -PHP Chinese website Q&A-PHP displays some garbled characters? -PHP Chinese website Q&A
Let’s take a look and learn.
mysql_query ( 'set names utf8' ); 把这个放在sql连接语句的下面。