Skip to content
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

PHP 8.1 error with Mysqli "The number of variables must match the number of parameters in the prepared statement" #19413

Closed
Starker3 opened this issue Jun 26, 2022 · 6 comments
Labels
worksforme The issue cannot be reproduced and things work as intended.

Comments

@Starker3
Copy link
Contributor

When running the core:archive command on a Matomo install using PHP 8.1, the following error is returned:

Got invalid response from API request: ?module=API&method=CoreAdminHome.archiveReports&idSite=2&period=day&date=2022-06-15&format=json&segment=countryCode%3D%3DPK&trigger=archivephp. 
Response was '{"result":"error","message":"The number of variables must match the number of parameters in the prepared statement on \/var\/www\/piwik\/libs\/Zend\/Db\/Statement\/Mysqli.php(208)
#0 [internal function]: mysqli_stmt->bind_param()
#1 \/var\/www\/piwik\/libs\/Zend\/Db\/Statement\/Mysqli.php(208): mysqli_stmt->execute()
#2 \/var\/www\/piwik\/libs\/Zend\/Db\/Statement.php(300): Zend_Db_Statement_Mysqli->_execute()
#3 \/var\/www\/piwik\/libs\/Zend\/Db\/Adapter\/Abstract.php(479): Zend_Db_Statement->execute()
#4 \/var\/www\/piwik\/core\/DataAccess\/LogAggregator.php(325): Zend_Db_Adapter_Abstract->query()
#5 \/var\/www\/piwik\/core\/DataAccess\/LogAggregator.php(351): Piwik\\DataAccess\\LogAggregator->createTemporaryTable()
#6 \/var\/www\/piwik\/core\/DataAccess\/LogAggregator.php(561): Piwik\\DataAccess\\LogAggregator->generateQuery()
#7 \/var\/www\/piwik\/core\/ArchiveProcessor\/PluginsArchiver.php(285): Piwik\\DataAccess\\LogAggregator->queryVisitsByDimension()
#8 \/var\/www\/piwik\/core\/ArchiveProcessor\/PluginsArchiver.php(102): Piwik\\ArchiveProcessor\\PluginsArchiver->aggregateDayVisitsMetrics()
#9 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(278): Piwik\\ArchiveProcessor\\PluginsArchiver->callAggregateCoreMetrics()
#10 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(176): Piwik\\ArchiveProcessor\\Loader->prepareAllPluginsArchive()
#11 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(159): Piwik\\ArchiveProcessor\\Loader->insertArchiveData()
#12 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(99): Piwik\\ArchiveProcessor\\Loader->prepareArchiveImpl()
#13 \/var\/www\/piwik\/core\/Context.php(75): Piwik\\ArchiveProcessor\\Loader->Piwik\\ArchiveProcessor\\{closure}()
#14 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(103): Piwik\\Context::changeIdSite()
#15 \/var\/www\/piwik\/plugins\/CoreAdminHome\/API.php(277): Piwik\\ArchiveProcessor\\Loader->prepareArchive()
#16 [internal function]: Piwik\\Plugins\\CoreAdminHome\\API->archiveReports()
#17 \/var\/www\/piwik\/core\/API\/Proxy.php(244): call_user_func_array()
#18 \/var\/www\/piwik\/core\/Context.php(28): Piwik\\API\\Proxy->Piwik\\API\\{closure}()
#19 \/var\/www\/piwik\/core\/API\/Proxy.php(335): Piwik\\Context::executeWithQueryParameters()
#20 \/var\/www\/piwik\/core\/API\/Request.php(266): Piwik\\API\\Proxy->call()
#21 \/var\/www\/piwik\/plugins\/API\/Controller.php(45): Piwik\\API\\Request->process()
#22 [internal function]: Piwik\\Plugins\\API\\Controller->index()
#23 \/var\/www\/piwik\/core\/FrontController.php(631): call_user_func_array()
#24 \/var\/www\/piwik\/core\/FrontController.php(169): Piwik\\FrontController->doDispatch()
#25 \/var\/www\/piwik\/core\/dispatch.php(32): Piwik\\FrontController->dispatch()
#26 \/var\/www\/piwik\/index.php(25): require_once('...')
#27 \/var\/www\/piwik\/core\/CliMulti\/RequestCommand.php(79): require_once('...')
#28 \/var\/www\/piwik\/vendor\/symfony\/console\/Symfony\/Component\/Console\/Command\/Command.php(257): Piwik\\CliMulti\\RequestCommand->execute()
#29 \/var\/www\/piwik\/vendor\/symfony\/console\/Symfony\/Component\/Console\/Application.php(874): Symfony\\Component\\Console\\Command\\Command->run()
#30 \/var\/www\/piwik\/vendor\/symfony\/console\/Symfony\/Component\/Console\/Application.php(195): Symfony\\Component\\Console\\Application->doRunCommand()
#31 [internal function]: Symfony\\Component\\Console\\Application->doRun()
#32 \/var\/www\/piwik\/core\/Console.php(135): call_user_func()
#33 \/var\/www\/piwik\/core\/Access.php(670): Piwik\\Console->Piwik\\{closure}()
#34 \/var\/www\/piwik\/core\/Console.php(136): Piwik\\Access::doAsSuperUser()
#35 \/var\/www\/piwik\/core\/Console.php(87): Piwik\\Console->doRunImpl()
#36 \/var\/www\/piwik\/vendor\/symfony\/console\/Symfony\/Component\/Console\/Application.php(126): Piwik\\Console->doRun()
#37 \/var\/www\/piwik\/console(32): Symfony\\Component\\Console\\Application->run()
#38 {main}","backtrace":"The number of variables must match the number of parameters in the prepared statement on \/var\/www\/piwik\/libs\/Zend\/Db\/Statement\/Mysqli.php(208)
#0 [internal function]: mysqli_stmt->bind_param()
#1 \/var\/www\/piwik\/libs\/Zend\/Db\/Statement\/Mysqli.php(208): mysqli_stmt->execute()
#2 \/var\/www\/piwik\/libs\/Zend\/Db\/Statement.php(300): Zend_Db_Statement_Mysqli->_execute()
#3 \/var\/www\/piwik\/libs\/Zend\/Db\/Adapter\/Abstract.php(479): Zend_Db_Statement->execute()
#4 \/var\/www\/piwik\/core\/DataAccess\/LogAggregator.php(325): Zend_Db_Adapter_Abstract->query()
#5 \/var\/www\/piwik\/core\/DataAccess\/LogAggregator.php(351): Piwik\\DataAccess\\LogAggregator->createTemporaryTable()
#6 \/var\/www\/piwik\/core\/DataAccess\/LogAggregator.php(561): Piwik\\DataAccess\\LogAggregator->generateQuery()
#7 \/var\/www\/piwik\/core\/ArchiveProcessor\/PluginsArchiver.php(285): Piwik\\DataAccess\\LogAggregator->queryVisitsByDimension()
#8 \/var\/www\/piwik\/core\/ArchiveProcessor\/PluginsArchiver.php(102): Piwik\\ArchiveProcessor\\PluginsArchiver->aggregateDayVisitsMetrics()
#9 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(278): Piwik\\ArchiveProcessor\\PluginsArchiver->callAggregateCoreMetrics()
#10 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(176): Piwik\\ArchiveProcessor\\Loader->prepareAllPluginsArchive()
#11 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(159): Piwik\\ArchiveProcessor\\Loader->insertArchiveData()
#12 \/var\/www\/piwik\/core\/ArchiveProcessor\/Loader.php(99): Piwik\\ArchiveProcessor\\Loader->prepareArchiveImpl()
#13 \/var\/www\/piwik\/core\/Context.php(75): Piwik\\ArchiveProcessor\\Lo ... 
#18 \/var\/www\/piwik\/console(32): Symfony\\Component\\Console\\Application->run()
#19 {main}"}'

Matomo version: 4.10.1
MySQL version: 10.3.31-MariaDB-log
PHP version: 8.1.7

For now we've asked the user to try switching the adapter to PDO to see if that temporarily resolves the issue.

@Starker3 Starker3 added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Jun 26, 2022
@sgiehl
Copy link
Member

sgiehl commented Jun 27, 2022

There was a similar report with a prepared statement error #19129, but that might be unrelated, as it did happen in a live query.
Nevertheless I tried to reproduce with archiving the same segment, but for me that worked without a problem. Might be good to get some additional details on the setup. Like used plugins,...

@Starker3
Copy link
Contributor Author

@sgiehl here are their installed plugins:

Plugins Activated:

API, Actions, Annotations, BulkTracking, Contents, CoreAdminHome, CoreConsole, CoreHome, CorePluginsAdmin, CoreUpdater, CoreVisualizations, CoreVue, CustomDimensions, CustomJsTracker, CustomVariables 4.1.0, DBStats, Dashboard, DevicePlugins, DevicesDetection, Diagnostics, Ecommerce, Events, Feedback, GeoIp2, Goals, Heartbeat, ImageGraph, Insights, Installation, Intl, IntranetMeasurable, LanguagesManager, Live, Login, LoginSaml 4.1.2, Marketplace, MobileMessaging, Monolog, Morpheus, MultiSites, Overlay, PagePerformance, PrivacyManager, ProfessionalServices, Provider 4.0.3, Proxy, Referrers, Resolution, RssWidget, SEO, ScheduledReports, SegmentEditor, SitesManager, Tour, Transitions, TwoFactorAuth, UserCountry, UserCountryMap, UserId, UserLanguage, UsersManager, VisitFrequency, VisitTime, VisitorInterest, VisitsSummary, WebsiteMeasurable, Widgetize

Plugins Deactivated:

MobileAppMeasurable, TagManager

@sgiehl
Copy link
Member

sgiehl commented Jun 28, 2022

Hm... that doesn't look very special. I'm not able to reproduce that, so it might get hard to find the problem.
@Starker3 Is it possible to get some details on the failing query? It seems to happen here:

$readerDb->query($insertIntoStatement, $segmentSelectBind);

so maybe logging the query and the bound parameters in case of an error might help.

@Starker3
Copy link
Contributor Author

@sgiehl Would it be enough to run core:archive with -vvv ? Or should we enabled SQL profiling to get the full request?

@sgiehl
Copy link
Member

sgiehl commented Jun 29, 2022

I don't think -vvv would be enough. Guess you need to enabling logging of sql queries.

@Starker3
Copy link
Contributor Author

Starker3 commented Jul 6, 2022

Changing the adapter to PDO/MYSQL fixed the error here, so the user didn't get the SQL queries logged. Not sure if you wanted to keep this one open or rather close it since we can't reproduce @sgiehl ?

@sgiehl sgiehl closed this as completed Jul 15, 2022
@sgiehl sgiehl closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2022
@sgiehl sgiehl added worksforme The issue cannot be reproduced and things work as intended. and removed Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. labels Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
worksforme The issue cannot be reproduced and things work as intended.
Projects
None yet
Development

No branches or pull requests

2 participants