-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
20 lines (20 loc) · 896 Bytes
/
database.php
File metadata and controls
20 lines (20 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$databaseConnection = null;
function getConnection(){
include 'config.php';
$hostname = constant("SQL_SERVER_NAME"); //数据库服务器主机名,可以用IP代替
$database = constant("SQL_DATABASE"); //数据库名
$userName = constant("SQL_USERNAME"); //数据库服务器用户名
$password = constant("SQL_PASSWORD"); //数据库服务器密码
global $databaseConnection;
$databaseConnection = @mysql_connect($hostname, $userName, $password) or die (mysql_error()); //连接数据库服务器
mysql_query("set names 'gbk'"); //设置字符集
@mysql_select_db($database, $databaseConnection) or die(mysql_error());
}
function closeConnection(){
global $databaseConnection;
if($databaseConnection){
mysql_close($databaseConnection) or die(mysql_error());
}
}
?>