gpt4 book ai didi

php - PDO异常 : Invalid parameter number with message 'SQLSTATE[HY093]: Columns/Parameters are 1-based'

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:33 25 4
gpt4 key购买 nike

这个项目真的很难。我正在尝试访问具有各种字段的数据库,每个字段都有一个唯一的变量;但我仍然得到“列是基于 1 的”

堆栈跟踪

Notice: exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based' in C:\wamp\www\CTEC3110\includes\classes\cw_framework\class.CourseWorkDatabaseWrapper.php:80
Stack trace:
#0 C:\wamp\www\CTEC3110\includes\classes\cw_framework\class.CourseWorkDatabaseWrapper.php(80): PDOStatement->bindParam(0, '447950491677', 2)
#1 C:\wamp\www\CTEC3110\includes\classes\cw_download_message_data\class.CourseWorkDownloadMessageDataModel.php(357): CourseWorkDatabaseWrapper->safe_query('SELECT id FROM ...', Array)
#2 C:\wamp\www\CTEC3110\includes\classes\cw_download_message_data\class.CourseWorkDownloadMessageDataModel.php(181): CourseWorkDownloadMessageDataModel->do_check_if_data_exists()
#3 C:\wamp\www\CTEC3110\includes\classes\cw_framework\class.CourseWorkContainer.php(142): CourseWorkDownloadMessageDataModel->do_store_downloaded_message_data()
#4 C:\wamp\www\CTEC3110\includes\classes\cw_download_message_data\class.CourseWorkDownloadMessageDataController.php(15): CourseWorkContaine in C:\wamp\www\CTEC3110\includes\classes\cw_framework\class.CourseWorkDatabaseWrapper.php on line 102


$this->c_obj_stmt = $this->c_obj_database_handle->prepare($m_query_string);

// bind the parameters
if (sizeof($m_arr_query_parameters) > 0)
{
foreach ($m_arr_query_parameters as $m_param_keys)
{
var_dump($m_param_keys);

foreach ($m_param_keys as $m_param_key => $m_param_value)
{
$this->c_obj_stmt->bindParam($m_param_key, $m_param_value, PDO::PARAM_STR);
}
}
}

// execute the query
$m_execute_result = $this->c_obj_stmt->execute();
$this->c_arr_database_connection_messages['execute-OK'] = $m_execute_result;
$m_database_query_execute_error = false;

其中“$m_query_string”是:

SELECT id
FROM cw_messages
WHERE source = :source_terminal
AND destination = :destination_terminal
AND date = :message_date
AND time = :message_time
AND type = :message_type
AND reference = :message_reference
AND data = :message_data
LIMIT 1

这里是“$m_arr_query_parameters”:

Array ( [:source_terminal] => Array ( [0] => 447950491677 [1] => 447950491677 ) [:destination_terminal] => Array ( [0] => 447817814149 [1] => 447817814149 ) [:message_date] => Array ( [0] => 14/08/2014 [1] => 14/08/2014 [2] => 2014-08-14 [3] => 2014-08-14 ) [:message_time] => Array ( [0] => 18:57:31 [1] => 19:48:28 ) [:message_type] => Array ( [0] => SMS [1] => SMS ) [:message_reference] => Array ( [0] => 0 [1] => 0 ) [:message_data] => Array ( [0] => Test 3 [1] => Test at 20:48 ) ) 

这是 $m_param_keys 的 var 转储:

array (size=2) 0 => string '447950491677' (length=12) 1 => string '447950491677' (length=12)

最佳答案

您的转储显示 $m_param_keys 是一个数字键控数组。你实际上是在尝试做

->bindParam(0, 447950491677)

PDO 参数从 1 开始编号,而不是从 0 开始。而且您还使用了 NAMED 参数,因此也不允许通过数字偏移量进行绑定(bind)。绑定(bind)调用应该是

->bindParam(':source_terminal', $m_message_source)

关于php - PDO异常 : Invalid parameter number with message 'SQLSTATE[HY093]: Columns/Parameters are 1-based' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25327213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com