Zend Framework Error Invalid bind-variable name + Solution

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

If you encounter the error :

Invalid bind-variable name xxxxxx

When trying to use named bound parameters with Zend Framework, then you are probably using the Mysqli adapter. Unfortunately this doesn’t actually support named parameters, but the Exception message isn’t really clear on that, despite being thrown in this block of code:

 } else if ($val[0] == ':') {
	if ($this->_adapter->supportsParameters('named') === false) {
		/**
		 * @see Zend_Db_Statement_Exception
		 */
		require_once 'Zend/Db/Statement/Exception.php';
		throw new Zend_Db_Statement_Exception("Invalid bind-variable name '$val'");
	}
}

The Exception should really say:

You are trying to use named parameters with an adapter that doesn’t support them

The solution is easy, just switch your adapter from Mysqli to Pdo_Mysql


Tags: zend frameworkexceptionerrornamed parametersbind variable name