我在運行時創建數據庫和表。當我執行代碼時,它正在創建數據庫而不是表。它拋出一個錯誤:“沒有選擇數據庫”;請指導我。$sql = "CREATE DATABASE $db_name";if ($this->db->query($sql) === TRUE) { $errors = []; $table1 = "CREATE TABLE `login_detail` ( `id` int(100) UNSIGNED AUTO_INCREMENT PRIMARY KEY, `employee_id` varchar(100) NOT NULL, `full_name` varchar(150) NOT NULL, `password` varchar(100) NOT NULL, `role` varchar(50) NOT NULL, `profile_image` varchar(255) NOT NULL, `status` varchar(100) NOT NULL DEFAULT '1')"; $table2 = "INSERT INTO `login_detail` (`id`, `employee_id`, `full_name`, `password`, `role`, `profile_image`, `status`) VALUES (1, 'admin', 'admin', '21232f297a57a5a743894a0e4a801fc3', 'admin', 'uploads/profiles/admin.jpg', '1')"; $tables = [$table1, $table2]; foreach($tables as $k => $sql1){ $query = $this->db->query($sql1); if(!$query) $errors[] = "Table $k : Creation failed ($this->db->error)"; else $errors[] = "Table $k : Creation done"; } foreach($errors as $msg) { echo "$msg <br>"; }} else { echo "Error creating database: " . $this->db->error;}
- 1 回答
- 0 關注
- 120 瀏覽
添加回答
舉報
0/150
提交
取消