我正在使用许多数据库,我想知道是否可以连接mysqli并在以下情况下指定数据库:example
$mysqli = new mysqli("localhost", "user", "password", "database");
$req = $mysqli->query("SELECT * FROM `table` WHERE id = '1' ");
会变成
$mysqli = new mysqli("localhost", "user", "password");
$req = $mysqli->query("SELECT * FROM `database`.`table` WHERE id = '1' ");
我可以添加$mysqli->select_db("database");
但是如果有办法使用上面的查询,我想知道该怎么做。谢谢!
答案 0 :(得分:0)
是的,这个方法其实非常简单, 只是做
$mysqli = new mysqli("localhost", "user", "password");
$res = $mysqli->query("SHOW DATABASES");
while ($row = $res->fetch_assoc()) {
echo ($results, $row['Database'] . "\n");
}