Last active
May 19, 2016 23:56
-
-
Save onlylemi/a902d4d9ef43ecee5824f8ba1008642f to your computer and use it in GitHub Desktop.
【PHP】连接数据库通用代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting ( 0 ); | |
header ( 'Content-Type:text/html;charset=utf-8' ); | |
// 常量参数 | |
define ( 'DB_HOST', 'localhost' ); | |
define ( 'DB_USER', 'root' ); | |
define ( 'DB_PWD', 'root' ); | |
define ( 'DB_NAME', 'inerd' ); | |
// 1. 连接MYSQL服务器 | |
$conn = @mysql_connect ( DB_HOST, DB_USER, DB_PWD ); | |
// 2. 选择指定的数据库, | |
mysql_select_db ( DB_NAME, $conn ); | |
// 3. 设置字符集 | |
mysql_query ( 'SET NAMES UTF8' ); | |
// 4. 设置中国时区 | |
date_default_timezone_set ( 'PRC' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment