conn.php 486 B

1234567891011121314151617181920212223
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "123456";
  5. $tab = "hk7";
  6. // 创建连接
  7. $con = new mysqli($servername, $username, $password, $tab);
  8. $db = mysqli_select_db($con, $tab);
  9. mysqli_query($con, "set names utf8");
  10. // 检测连接
  11. if ($con->connect_error) {
  12. die("连接失败: " . $con->connect_error);
  13. }
  14. $GLOBALS['dbconfig'] = [
  15. 'host' => $servername,
  16. 'user' => $username,
  17. 'pwd' => $password,
  18. 'dbname' => $tab,
  19. ];
  20. $GLOBALS['con'] = $con;