summaryrefslogtreecommitdiff
path: root/connect.php
blob: 0a94c31c7ce849bbdf1bbf600eac2869a86d5113 (plain)
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
<?php require_once 'config.php'?>
<?php require_once 'db.php'?>

<?php

global $conn;

function execute_sql($sql) {
    global $conn;
    if($conn == NULL){
        // 创建连接
        $conn = new mysqli(DBConfig::$servername, DBConfig::$username, DBConfig::$password, DBConfig::$db_name);

        // 检测连接
        if ($conn->connect_error) {
            die("连接失败: " . $conn->connect_error);
            return ;
        } 
    }
    return mysqli_query($conn, $sql);
}

function get_last_insert_id() {
    global $conn;
    return mysqli_insert_id($conn);
}

?>