6

I am trying to get the slave status of my MySQL server using PHP's PDO implementation. 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 have also tried removing the ->execute() call, but it's the same result. Is there something completely obvious that I'm missing here? I've looked up and down the PDO::query documentation and it's not helping much.

Andrew Ellis
  • 1,175
  • 1
  • 12
  • 29

2 Answers2

5

Do you have permission to execute the query?

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);
    }
}
drew010
  • 68,777
  • 11
  • 134
  • 162
  • Yeah, that was exactly the problem. My replication user was not setup properly. I'll accept your answer once the 3 minute limit thing is gone. Cheers! – Andrew Ellis Jul 16 '12 at 18:30
  • 2
    Ah I see you found it out about the same time I did, I tested it on my system and got the error about insufficient privileges so was figuring we had the same problem. – drew010 Jul 16 '12 at 18:33
1

This was actually due to a permission's issue on the server. I incorrectly setup my replication user so replication itself wasn't even working.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Andrew Ellis
  • 1,175
  • 1
  • 12
  • 29