Php connection to mysql two methods mysql garbled problem

Source: Internet
Author: User
Php connection to mysql two methods mysql garbled problem

  1. // 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;
  2. $ Mysqli = new mysqli ("127.0.0.1", "username", password "," database name ");
  3. $ Query = "select * from table order by theindex desc ";
  4. $ Mysqli-> query ("set names gb2312"); // note that garbled characters are not added here.
  5. $ Result = $ mysqli-> query ($ query );
  6. // The printf () function outputs formatted strings.
  7. While (list ($ name, $ theindex) = $ result-> fetch_row ())
  8. Echo ("
    ". $ Name. $ theindex );
  9. $ Con = mysql_connect ("localhost", "username", "password ");
  10. If ($ con ){
  11. Mysql_query ("set names 'gb2312 '");
  12. Mysql_select_db ("database name", $ con); // note that garbled characters are not added here.
  13. $ Rs = mysql_query ("select * from table order by theindex desc;", $ con );
  14. If ($ rs ){
  15. Echo ("
  16. While ($ row = mysql_fetch_assoc ($ rs ))
  17. "
  18. "
  19. "
  20. }
  21. {
  22. Echo"
  23. Mysql_free_result ($ rs );
  24. }
  25. Echo ("
  26. "); ". ". ". ";
    $ Row [theindex]$ Row [name]
    ");
  27. Mysql_close ($ con );
  28. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.