Hallo,
ich hab folgende Function in einem Model
PHP-Code:
public static function countStats($field, $arrWhere, $arrValue) {
$table = static::$strTable;
$obj = Database::getInstance()->prepare("SELECT ".$field." as cnt
FROM ".$table."
WHERE ".implode(" AND ", $arrWhere))->execute($arrValue);
return $obj->cnt;
}
im Controller frage ich dies so ab:
PHP-Code:
TestModel::countStats('SUM(playtime)', ['published=?', 'active=?'], [1,1]);
bis 4.13.x hat da swohl auch alles funktioniert, jetzt in Contao 5.3 meldet er folgendes und die Db Abfrage sieht so aus:
Code:
An exception occurred while executing a query: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Code:
SELECT SUM(playtime) AS cnt FROM tl_my_test WHERE published=? AND Lossy=?
Parameter
Code:
a:2:{i:0;i:1;i:1;i:1;}
nutze ich nur
PHP-Code:
TestModel::countBy(['published=?','active=?'], [1,1]);
sieht das ganze so aus
Code:
SELECT COUNT(*) AS count FROM tl_my_test WHERE published=? AND Lossy=?
Parameter
Wieso bzw wo macht er dann ein serialize array drauß, in der 4.13. war dies nicht der Fall mit dem selben Code
Edit:
contao/core-bundle', '4.13', 'Using "%s()" with an array parameter has been deprecated and will no longer work in Contao 5.0. Use argument unpacking via ... instead.
muss dann wohl so aussehen
PHP-Code:
public static function countStats($field, $arrWhere, $arrValue) {
$table = static::$strTable;
$obj = Database::getInstance()->prepare("SELECT ".$field." as cnt
FROM ".$table."
WHERE ".implode(" AND ", $arrWhere))->execute(...$arrValue);
return $obj->cnt;
}
Lesezeichen