'Zend_Db_Statement_Exception' with message 'Invalid bind-variable name ':1'

雨燕双飞 提交于 2019-12-10 17:43:22

问题


Good day,

Background Info:

Client's hosting server is being upgraded from PHP 5.2 to PHP 5.3. The client's app breaks when tested on PHP 5.3. Specifically the insert and update methods are the ones which are breaking the app. The app coded in Zend Framework v1.7.2.

We have tried simply upgrading the Zend Framework core, however it seems that the previous developers made changes to the core, which causes the app to completely break when the framework has been upgraded.

Problem

The best solution was to add a class called AppModel which extends Zend_Db_Table_Abstract and then simply overwrite the insert and update methods. All models in this app extend the AppModel class. This works fine until checkbox data or radio button data has to be written to the database.

The app now throws the following error:

Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'Invalid bind-variable name ':1'' in ....

NB. Full error message at the bottom

I have been looking for a solution on the internet for days in vain. One of the solutions I found was to change Mysqli to Pdo_Mysql. however it seems that there is no such class in the framework. There is the class Pdo which throws the same error as Mysqli.

Please help!

Please excuse my English. If you need clarification please dont hesitate to contact me. thanks in advance

The following is code sample from the AppModel class:

class AppModel extends Zend_Db_Table_Abstract{
                //PHP 5.3 fix   
                public function insert(array $data) {

                    //array to carry data for holding data
                    $ins_data = array();

                    foreach($data as $table => $value){
                        $ins_data['tables'][] = $table;
                        $ins_data['values'][] = mysql_escape_string($value);
                    }

                    $db = Zend_Registry::get('db');                    

                    $ins_query = ' INSERT INTO '.  $this->_name.' ('.implode($ins_data['tables'], ', ').')
                                   VALUES ("'.implode($ins_data['values'], '", "').'")'; 
                    $ins_action = new Zend_Db_Statement_Mysqli($db, $ins_query);
                    $ins_action->execute();
                    return $db->lastInsertId();
                }        
}

Complete error message:

Fatal error: 
    Uncaught exception 'Zend_Db_Statement_Exception' 
    with message 'Invalid bind-variable name ':1'' 
    in C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php:143 
Stack trace: 
#0 C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php(108): Zend_Db_Statement->_parseParameters(' UPDATE user_te...') 
#1 C:\wamp\www\schoolnet\application\AppModel.php(43): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), ' UPDATE user_te...') 
#2 C:\wamp\www\schoolnet\application\modules\user\helpers\UserHelper.php(530): AppModel->update(Array, 'user_id = 6') 
#3 C:\wamp\www\schoolnet\application\modules\user\controllers\UserController.php(533): user_helpers_UserHelper->teacherUpdate(Array, 6) 
#4 C:\wamp\www\schoolnet\application\modules\user\controllers\UserController.php(300): UserController->teacherUpdateDetails(Array, 6) 
#5 C:\wamp\www\schoolnet\public_html\Zend\Controller\Action.php(503): UserController->detailseditAction() 
#6 C:\wamp\www\schoolnet\public_html\Zend\Controller\Dispatcher\Standard.php(285): Zend_Control in C:\wamp\www\schoolnet\public_html\Zend\Db\Statement.php on line 143

来源:https://stackoverflow.com/questions/8893561/zend-db-statement-exception-with-message-invalid-bind-variable-name-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!