zendframework/zend-db

DbAdapter query parameters in PDO

Opened this issue · 3 comments

$dbAdapter->query('SET @@session.time_zone = :tz', [
    ':tz' => $timeZoneName,
]);

After #224, this line throws an error "Invalid parameter number: parameter was not defined"

This method changes param name before binding, but do not change it in query string

/**
 * @param string $name
 * @param string|null $type
 * @return string
*/
public function formatParameterName($name, $type = null)
{
    if ($type === null && ! is_numeric($name) || $type == self::PARAMETERIZATION_NAMED) {
        // using MD5 because of the PDO restriction [A-Za-z0-9_] for bindParam name
        return ':' . md5($name);
    }

    return '?';
}

@ArtemChornovol scenario above needs tests - not sure what formatParameterName is supposed to help with here.

@ArtemChornovol damn, you right! The #224 introduced an issue, I completely failed to fix #35 not considering the params in the original SQL statement. This story is the proof that we need more tests for zend-db!!! I need to revert #224 and provide a new release 2.9.1. I'm working on it.