【发布时间】:2017-05-04 23:54:19
【问题描述】:
好的,所以我遇到了一个非常奇怪的 PDOException,我似乎无法理解。这是生成的异常:
PDOException: SQLSTATE[IMSSP]: Tried to bind parameter number 65536. SQL Server supports a maximum of 2100 parameters. in D:\Work\CEUR16-004\Project\www_root\includes\scripts\php\libCore\products.php:169
Stack trace:
#0 D:\Work\CEUR16-004\Project\www_root\includes\scripts\php\libCore\products.php(169): PDOStatement->execute()
#1 D:\Work\CEUR16-004\Project\www_root\includes\pages\products\products.php(5): ProductCore->build_product_list()
#2 D:\Work\CEUR16-004\Project\www_root\index.php(27): include('D:\\Work\\CEUR16-...')
#3 {main}
这里是它引用的代码:
public function build_product_list()
{
// This function builds the product list visible on the main site (guests only)
try
{
if($this->product_type_id == "999")
{
$query = 'SELECT sp.product_id, sp.product_name, sp.product_price, pt.product_type_name FROM shop_products AS sp LEFT JOIN product_types AS pt ON sp.product_type_id = pt.product_type_id ORDER BY sp.product_type_id ASC'; // Line 161
}
else
{
$query = 'SELECT sp.product_id, sp.product_name, sp.product_price, pt.product_type_name FROM shop_products AS sp LEFT JOIN product_types AS pt ON sp.product_type_id = pt.product_type_id WHERE sp.product_type_id = :product_type_id ORDER BY sp.product_id ASC';
}
$stmt = $this->dbcore_prod_core->dbc->prepare($query);
$stmt->bindParam(':product_type_id', $this->product_type_id, PDO::PARAM_INT);
$stmt->execute(); // Line 169
// Function continues below...
现在,仅当 $this->product_type_id 等于 999 时才会生成此异常,后者在第 161 行运行查询(在上面的代码中注释)。我已经直接在服务器上运行了查询,它返回了预期的结果,那么为什么 PDO 会抛出异常呢?
【问题讨论】:
标签: php sql-server pdo