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

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
User avatar
R2D2
Posts: 170
Joined: Tue Dec 27, 2005 5:02 pm
Location: Stuttgart, Germany

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

Post 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?
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

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

Post by rockedge »

does it work now with the fix you did here: viewtopic.php?f=38&t=28014 ???
User avatar
R2D2
Posts: 170
Joined: Tue Dec 27, 2005 5:02 pm
Location: Stuttgart, Germany

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

Post by R2D2 »

Unfortunately not. :(

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

Image
User avatar
R2D2
Posts: 170
Joined: Tue Dec 27, 2005 5:02 pm
Location: Stuttgart, Germany

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

Post 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 ~ #
User avatar
kitkat
Posts: 193
Joined: Sun Jan 27, 2019 5:17 pm

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

Post 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
Post Reply