db.class.php 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. session_start();
  3. require_once "config.inc.php";
  4. if (IN_DEBUG && is_file(".debug/debug.php")) {
  5. include_once ".debug/debug.php";
  6. }
  7. require_once IN_ROOT . "vendor/autoload.php";
  8. use think\facade\Db;
  9. Db::setConfig(["default" => "mysql", "connections" => ["mysql" => ["type" => "mysql", "hostname" => IN_DBHOST, "username" => IN_DBUSER, "password" => IN_DBPW, "database" => IN_DBNAME, "charset" => IN_DBCHARSET, "prefix" => IN_DBTABLE, "debug" => true]]]);
  10. $myConfig = IN_ROOT . "source/system/my.php";
  11. if (!is_file($myConfig)) {
  12. $res = db("config")->select();
  13. $conf = ["<?php"];
  14. foreach ($res as $k => $v) {
  15. if (!defined($v["name"])) {
  16. $conf[] = "define('" . $v["name"] . "','" . $v["value"] . "');";
  17. }
  18. }
  19. file_put_contents($myConfig, implode("\n", $conf));
  20. }
  21. require_once $myConfig;
  22. require_once IN_ROOT . "source/system/function_common.php";
  23. list($info, $module, $action) = path_info();
  24. function db($_var_0 = '')
  25. {
  26. return Db::name($_var_0);
  27. }
  28. function model($_var_1 = '')
  29. {
  30. return ("\\app\\model\\" . $_var_1)::name($_var_1);
  31. }