-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phalcon\Db\Adapter\Pdo messes up the input data #2111
Comments
PDOStatement::bindParam passes values as references so it could eventually transform the passed values. |
As others say – http://www.php.net/manual/en/pdostatement.bindparam.php#94711 |
Actually, can we not close this. I've looked into this further and it seems to be a very painful experience laid out here – http://stackoverflow.com/q/22084499/458356 Can we somewhere along those lines https://github.com/phalcon/cphalcon/blob/1.3.0/ext/db/adapter/pdo.c#L430 copy the value and pass that copy as a reference to retain values in the original array from changing? Or at least limit that change to the supplied array, not arrays it's been copied from? Phalcon documentation doesn't imply that the value is being passed as reference + I don't see any sensible reason why one would want to get such results. But it might be just agonised myself… 🍻 |
Or well, as Mike suggests: Use bindValue instead of bindParam and then the original variables won't be changed. |
Works like a charm! Can we keep it mommy??? :) |
If you install php-mysqlnd instead if php-mysql, bindValue will not convert variable from string to int. Additional, result set from database will return correct variable types (if it's integer it will be returned integer). Php-mysql converts all variables to string. |
Andres, regarding your comment in #2101, I'm not sure what you meant by 'there are no applications' or how it relates to this issue. Is there any reason why bindParam used over bindValue? In the nutshell:
All values in Phalcon are binded at the time of executing the query (correct if I'm wrong). This means that even if you'd want to change referenced values, that will have no affect on the result (query will be already sent by the time you can do that). In other words the functionality of bindParam is not utilised, but creates problems as per my situation. |
This works with mysqlnd driver and these two attributes set to false:
|
@kowach, I tried
You do When fetching rows I don't want to configure every query params types manually – that's the whole point. Currently to keep the parameters unmodified you can do this with each query (exactly what you did in your example).
|
Also, the example above works fine without |
Fix for #2111 – replacing bindParam to bindValue to avoid unexpected reference changes
This works for me. Install php5-mysqlndsudo apt-get install php5-mysqlnd OK Edit services.php$di->set('db', function () use ($config) {
$connection = new MysqlAdapter([
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
'charset' => $config->database->charset,
'options' => [
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_STRINGIFY_FETCHES => false,
]
]);
return $connection;
}); Test$robot = Robot::findFirst();
var_dump($robot->id); shows |
@ryomo's answer worked |
That drove me ABSOLUTE NUTTTTS!!! After making this call with $params array of
int
values, those values become strings.It's crazy, even if I do array_values I end up with the same shit:
Can we not use references in such calls? When we use references in C, does it actually help with anything or are they treated by zend compiler in the same way they are in PHP? Because if they do – it might be completely pointless. This might be a really dumb question, sorry, I'm taking the shot.
The text was updated successfully, but these errors were encountered: