Run "show slave status" with PHP PDO

I am trying to get the status of a slave MySQL server using PHP PDO. Running fetchAll() returns an empty array.

 // DB IP, name, username, and password are fake here. I can connect. $db = new PDO('mysql:host=192.168.0.0;dbname=production', 'username', 'password'); $result = $db->query("SHOW SLAVE STATUS"); $result->execute(); if ($result != false) { $slave = $result->fetchAll(PDO::FETCH_ASSOC); } 

I also tried removing the call ->execute() , but this is the same result. Is there something completely obvious that I'm missing here? I looked at the PDO :: query documentation and did not help much.

+6
source share
2 answers

Do you have permission to execute the request?

Try:

 $db = new PDO('mysql:host=192.168.0.0;dbname=production', 'username', 'password'); $result = $db->query("SHOW STATUS"); if (!$result) { echo $db->errorInfo()[2]; // php 5.4 } else { foreach($result->fetchAll() as $row) { var_dump($row); } } 
+3
source

This was due to a permission issue on the server. I misconfigured my replication user, so replication itself didn’t even work.

+1
source

Source: https://habr.com/ru/post/920619/


All Articles