这是我的代码:
$Limit=5;
$sql = 'SELECT * FROM [dbo].[table_name] ORDER BY [count] DESC LIMIT :limit';
$stmt = $db->prepare($sql);
$stmt->bindValue(':limit', (int) $Limit, PDO::PARAM_INT);
$results = $stmt->execute();
这里出现错误:
致命错误:未捕获的 PDOException:SQLSTATE[HY090]:无效的字符串或缓冲区长度:[FreeTDS][SQL Server]无效的字符串或缓冲区长度
知道我做错了什么吗?
使用 top 尝试此查询
$Limit = 5;
$sql = 'SELECT TOP :limit * FROM [dbo].[table_name] ORDER BY [count] DESC';
$stmt = $db->prepare($sql);
$stmt->bindValue(':limit', (int) $Limit, PDO::PARAM_INT);
$results = $stmt->execute();