PHP connection MySQL 2 methods summary and prevent garbled _php tips

Source: Internet
Author: User

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

Copy Code code as follows:

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 no garbled here
$rs = mysql_query ("SELECT * from table order by theindex desc;", $con);
if ($rs) {
Echo ("<table border=1>");
while ($row = Mysql_fetch_assoc ($rs))
{
echo "<tr>".
"<td> $row [theindex]</td>".
"<td> $row [name]</td>".
"</tr>";
}
Mysql_free_result ($RS);
}
Echo ("</table>");
Mysql_close ($con);
}

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.