-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
54 lines (44 loc) · 1.16 KB
/
common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
//从表单获取数据
function _POST($value){
return $_POST[$value]=isset($_POST[$value])?$_POST[$value]:NULL;
}
//连接数据库
function connect_mydb(){
global $mydb;
$mydb = mysqli_connect("localhost","root","","accountbook");
if (!$mydb)
{
die('链接不到数据库');
}
}
//选择数据库
function select_mydb(){
global $mydb;
mysqli_select_db($mydb,'accountbook');
mysqli_query($mydb,'SET NAMES UTF8');
}
//执行sql语句
function query($sql){
global $mydb;
$result= mysqli_query($mydb,$sql) or die('SQL执行失败'.mysqli_error($mydb).mysqli_errno($mydb));
return $result;
}
//查找数据all方法
function fetch_all($sql){
global $mydb;
$row=mysqli_fetch_all(query($sql),MYSQLI_ASSOC) or die('SQL执行失败'.mysqli_error($mydb).mysqli_errno($mydb));
return $row;
}
//查找数据array方法
function fetch_array($sql){
global $mydb;
$row=mysqli_fetch_array(query($sql),MYSQLI_ASSOC) or die('SQL执行失败'.mysqli_error($mydb).mysqli_errno($mydb));
return $row;
}
//查找数据row方法
function fetch_row($data){
$row=mysqli_fetch_row($data);
return $row;
}
?>