在PHP中使用sqlsrv_query从数据库中获取表的问题,可以通过以下步骤解决:
$serverName = "server_name";
$connectionOptions = array(
"Database" => "database_name",
"Uid" => "username",
"PWD" => "password"
);
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
$query = "SELECT * FROM INFORMATION_SCHEMA.TABLES";
$result = sqlsrv_query($conn, $query);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
echo "Table Name: " . $row['TABLE_NAME'] . "<br>";
echo "Table Type: " . $row['TABLE_TYPE'] . "<br>";
// 其他表信息...
}
需要注意的是,以上代码只是一个简单的示例,实际应用中可能需要根据具体需求进行适当的修改和优化。
推荐的腾讯云相关产品:腾讯云数据库SQL Server,产品介绍链接地址:https://cloud.tencent.com/product/cdb_sqlserver
领取专属 10元无门槛券
手把手带您无忧上云