PHP connection MySQL 2 ways to summarize and prevent garbled

Source: Internet
Author: User
Tags ini

  This article is mainly on the PHP connection to MySQL 2 methods summary and to prevent garbled problems were introduced in detail, the need for friends can come to the reference, I hope to help you.

MySQL configuration   error information for PHP: Class ' mysqli ' not found in   answer:1. In Conf/php.ini, the vim uses "/php_mysql" to search for Extension=php_ Mysql.dll, remove the front ";"   add extension=php_mysqli.dll at the same time below;   Note that the rear DLL has an extra I 2. /extension_dir Check if the path is correct;   3. Find the ext/directory and put the Php_mysql.dll,php_mysqli.dll two files under Copy to%systemroot%/system32.   4. Restart Service   Connection database   code is as follows:  //in Conf/php.ini, in vim with "/php_mysql" search to Extension=php_mysql.dll, remove the front of ";", At the same time add extension=php_mysqli.dll below; $mysqli = new Mysqli ("127.0.0.1", "username", "password", "library name"); $query = "SELECT * from   form ORDER by theindex DESC"; $mysqli->query ("SET NAMES gb2312");/note this will not add garbled $result = $mysqli->query ($query);    //printf () function output formatted string while (list ($name, $theindex) = $result->fetch_row ())         E Cho ("<br/>". $name. $theindex);   $con = mysql_connect ("localhost", "username", "password"); if ($con) {        mysql_query ("Set names ' gb2312");         mysql_select_db ("library name ", $con)//Note This will not add garbled                               &NBS P $rs = mysql_query ("Select * from   form ORDER by theindex desc;", $con);                                 if ($rs) {                                   EC Ho ("<table border=1>");                                   &NB Sp     while ($row = Mysql_fetch_assoc ($rs))                     &N Bsp                     {              & nbsp                                 echo "< Tr> ".                                       &N Bsp         "<td> $row [theindex]</td>".                                   &NB Sp             "<td> $row [name]</td>".                                   &NB Sp             "</tr>";                                   &NB Sp    }                               & nbsp         mysql_free_result ($RS);                                       }                           & nbsp             echo ("</table>");         mysql_close ($con); }  
Related Article

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.