PHP 2 ways to connect MySQL and prevent garbled

Source: Internet
Author: User
Tags ini

MySQL Configuration for PHP

Error message: Class ' mysqli ' not found in

Answer:
1. In the Conf/php.ini, in vim with "/php_mysql" search to Extension=php_mysql.dll, remove the front of the ";",

At the same time add extension=php_mysqli.dll below;

Note that the back of the DLL is a little more I
2. "/extension_dir" Check whether the path is correct;
3. Locate the ext/directory and put the Php_mysql.dll,php_mysqli.dll two files under Copy to%systemroot%/system32.
4. Restart Service

Connecting to a database
In the Conf/php.ini, in vim with "/php_mysql" search to Extension=php_mysql.dll, remove the front of the ";" At the same time add extension=php_mysqli.dll below;
$mysqli = new Mysqli ("127.0.0.1", "username", "password", "library name");
$query = "SELECT * from table ORDER by theindex DESC";
$mysqli->query ("SET NAMES gb2312");/note no garbled here
$result = $mysqli->query ($query);

printf () function output formatted string
while (list ($name, $theindex) = $result->fetch_row ())
Echo ("<br/>". $name. $theindex);

$con = mysql_connect ("localhost", "username", "password");


if ($con) {


mysql_query ("Set names ' gb2312 '");


mysql_select_db ("library name", $con);/Note that there will be no garbled


$rs = mysql_query ("SELECT * from table order by theindex desc;", $con);


if ($rs) {


Echo ("&lt;table border=1&gt;");


while ($row = Mysql_fetch_assoc ($rs))


                                        {


echo "&lt;tr&gt;".


"&lt;td&gt; $row [theindex]&lt;/td&gt;".


"&lt;td&gt; $row [name]&lt;/td&gt;".


"&lt;/tr&gt;";


}


mysql_free_result ($RS);


                                        }


Echo ("&lt;/table&gt;");


mysql_close ($con);


}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.