Php connection to mysql two methods mysql garbled problem
- // In conf/php. ini, use "/php_mysql" in vim to search for extension = php_mysql.dll, remove the previous ";", and add extension = php_mysqli.dll below;
- $ Mysqli = new mysqli ("127.0.0.1", "username", password "," database name ");
- $ Query = "select * from table order by theindex desc ";
- $ Mysqli-> query ("set names gb2312"); // note that garbled characters are not added here.
- $ Result = $ mysqli-> query ($ query );
- // The printf () function outputs formatted strings.
- While (list ($ name, $ theindex) = $ result-> fetch_row ())
- Echo ("
". $ Name. $ theindex );
- $ Con = mysql_connect ("localhost", "username", "password ");
- If ($ con ){
- Mysql_query ("set names 'gb2312 '");
- Mysql_select_db ("database name", $ con); // note that garbled characters are not added here.
- $ Rs = mysql_query ("select * from table order by theindex desc;", $ con );
- If ($ rs ){
- Echo ("
- While ($ row = mysql_fetch_assoc ($ rs ))
- "
- "
- "
- }
- {
- Echo"
- Mysql_free_result ($ rs );
- }
- Echo ("
");
".
| $ Row [theindex] | ".
$ Row [name] | ".
";
");
- Mysql_close ($ con );
- }
|