diff options
Diffstat (limited to 'connect.php')
-rw-r--r-- | connect.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/connect.php b/connect.php new file mode 100644 index 0000000..8787da3 --- /dev/null +++ b/connect.php @@ -0,0 +1,27 @@ +<?php require_once 'config.php'?> + +<?php + +global $conn; + +function execute_sql($sql) { + global $conn; + if($conn == NULL){ + // 创建连接 + $conn = new mysqli(Config::$servername, Config::$username, Config::$password, Config::$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); +} + +?>
\ No newline at end of file |