Page 1 of 1

[ZM API] Database connection "Mysql" is missing, or could not be created

Posted: Sat Feb 02, 2019 1:56 pm
by R2D2
Hi,

When i call in the Browser "http://server01/zm/api/monitors.json", i get the following issue:

Code: Select all

{ "code": 500, "name": "Database connection "Mysql" is missing, or could not be created.", "message": "SQLSTATE[HY000] [2002] ", "url": "\/zm\/api\/monitors.json" }
error.log:

Code: Select all

2019-02-02 13:52:29 Error: [MissingConnectionException] Database connection "Mysql" is missing, or could not be created.
Exception Attributes: array (
  'class' => 'Mysql',
  'message' => 'SQLSTATE[HY000] [2002] ',
  'enabled' => true,
)
Request URL: /zm/api/monitors.json
Stack Trace:
#0 /usr/share/zoneminder/www/api/lib/Cake/Model/Datasource/DboSource.php(271): Mysql->connect()
#1 /usr/share/zoneminder/www/api/lib/Cake/Model/ConnectionManager.php(105): DboSource->__construct(Array)
#2 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(3646): ConnectionManager::getDataSource('default')
#3 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(1162): Model->setDataSource('default')
#4 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(3673): Model->setSource('Monitors')
#5 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(1394): Model->getDataSource()
#6 /usr/share/zoneminder/www/api/app/Plugin/CakePHP-Enum-Behavior/Model/Behavior/EnumBehavior.php(34): Model->schema()
#7 /usr/share/zoneminder/www/api/lib/Cake/Model/BehaviorCollection.php(145): EnumBehavior->setup(Object(Monitor), Array)
#8 /usr/share/zoneminder/www/api/lib/Cake/Model/BehaviorCollection.php(66): BehaviorCollection->load('CakePHP-Enum-Be...', Array)
#9 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(781): BehaviorCollection->init('Monitor', Array)
#10 [internal function]: Model->__construct(NULL)
#11 /usr/share/zoneminder/www/api/lib/Cake/Utility/ClassRegistry.php(169): ReflectionClass->newInstance(Array)
#12 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(741): ClassRegistry::init('Monitor')
#13 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(368): Controller->loadModel('Monitor')
#14 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(406): Controller->__isset('Monitor')
#15 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(812): Controller->__get('Monitor')
#16 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(614): CrudComponent->_setModelProperties()
#17 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(751): CrudComponent->getSubject()
#18 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(728): CrudComponent->_loadListener('RelatedModels')
#19 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(169): CrudComponent->_loadListeners()
#20 /usr/share/zoneminder/www/api/lib/Cake/Utility/ObjectCollection.php(128): CrudComponent->initialize(Object(MonitorsController))
#21 /usr/share/zoneminder/www/api/lib/Cake/Event/CakeEventManager.php(243): ObjectCollection->trigger('initialize')
#22 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(677): CakeEventManager->dispatch(Object(CakeEvent))
#23 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(189): Controller->startupProcess()
#24 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(MonitorsController), Object(CakeRequest))
#25 /usr/share/zoneminder/www/api/app/webroot/index.php(107): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#26 {main}
Does anyone know, how to fix this?

Re: [ZM API] Database connection "Mysql" is missing, or could not be created

Posted: Sat Feb 02, 2019 2:40 pm
by rockedge
does it work now with the fix you did here: viewtopic.php?f=38&t=28014 ???

Re: [ZM API] Database connection "Mysql" is missing, or could not be created

Posted: Sat Feb 02, 2019 3:03 pm
by R2D2
Unfortunately not. :(

After i got the API working, i stumbled over this Problem.

Image

Re: [ZM API] Database connection "Mysql" is missing, or could not be created

Posted: Sun Feb 03, 2019 3:28 pm
by R2D2
I'm not sure if my php.ini is correct.

Maybe someone with a working API can post the output of:
grep ^mysql $(php --ini |grep Loaded |awk '{print $4 }')
This is my output:

Code: Select all

server01 ~ # grep ^mysql  $(php --ini |grep Loaded |awk '{print $4 }')
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
server01 ~ #

Re: [ZM API] Database connection "Mysql" is missing, or could not be created

Posted: Mon Feb 04, 2019 11:42 am
by kitkat

Code: Select all

$ grep ^mysql $(php --ini |grep Loaded |awk '{print $4 }')
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off