ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
~~~ //todo 读取数据库字段 start if (empty($this->config['database'])) { $configFile = APP_PATH . "wp-config.php"; if (!file_exists($configFile)) { res(1002, "接口配置异常,无法正常读取配置信息"); } $table_prefix = ''; $contents = file_get_contents($configFile); preg_match('/\$table_prefix\s*=\s*[\'|"](.+)[\'|"]/', $contents, $match); $table_prefix = $match[1]; preg_match('/define\(\s*[\'|"]DB_NAME[\'|"],\s*[\'|"](.+)[\'|"]/', $contents, $match); $dbName = $match[1]; preg_match('/define\(\s*[\'|"]DB_USER[\'|"],\s*[\'|"](.+)[\'|"]/', $contents, $match); $dbUser = $match[1]; preg_match('/define\(\s*[\'|"]DB_PASSWORD[\'|"],\s*[\'|"](.+)[\'|"]/', $contents, $match); $dbPassword = $match[1]; preg_match('/define\(\s*[\'|"]DB_HOST[\'|"],\s*[\'|"](.+)[\'|"]/', $contents, $match); $dbHost = $match[1]; preg_match('/define\(\s*[\'|"]DB_CHARSET[\'|"],\s*[\'|"](.+)[\'|"]/', $contents, $match); $dbCharset = $match[1]; $hostArr = explode(":", $dbHost); $this->config['database'] = array( 'host' => $hostArr[0], 'port' => empty($hostArr[1]) ? '3306' : $hostArr[1], 'user' => $dbUser, 'password' => $dbPassword, 'database' => $dbName, 'charset' => $dbCharset, 'prefix' => $table_prefix ); } //todo 读取数据库字段 end ~~~