0

This is killing me, and probably I'm just making a typo that I can't see.

Why is this validation not working?

<?php

$db = 'database';
$host = 'host';
$port = port;
$usr = 'username';
$pwd = 'password';
$db_status = array(
  'global_status'=>"",
  'slave_status'=>array()
);

$db = new mysqli(
      $host, $usr, $pwd, NULL, $port
  );

$qry = "SHOW GLOBAL STATUS LIKE 'Slave_running'";

$stmt = $db->query($qry);

while ($row = $stmt->fetch_assoc()) {
  $db_status['global_status']=$row['Value'];
}

$qry = "SHOW SLAVE STATUS";

$stmt = $db->query($qry);

while ($row = $stmt->fetch_assoc()) {
  $db_status['slave_status'] = $row;
}

$gbst = $db_status['global_status'];
$siostate = $db_status['slave_status']['Slave_IO_State'];
$siorunning = $db_status['slave_status']['Slave_IO_Running'];
$ssqlrunning = $db_status['slave_status']['Slave_SQL_Running'];
$lastioErrno = $db_status['slave_status']['Last_IO_Errno'];
$lastioError = $db_status['slave_status']['Last_IO_Error'];
$lastiotimestamp = $db_status['slave_status']['Last_IO_Error_Timestamp'];

if ($gbst === "OFF" || 
  $siostate !== "Running" || 
  $siorunning !== "Yes" ||
  $ssqlrunning !== "Yes") {

I am getting an error in the console reading:

PHP Parse error: syntax error, unexpected '$siostate' (T_VARIABLE) in /home/esantos/Crons/check_database_slave.php on line 50

Any ideas?

  • The code you are showing seems fine; the error must reside in a part of the code you're not showing us. Provide a [mcve], maybe? – domsson Apr 27 '17 at 23:22
  • Looks like you've got some kind of special character in there – John Conde Apr 27 '17 at 23:22
  • Copy & Pasted your code, it worked for me, something that comes before it is most likely the cause. – Barry Thomas Apr 27 '17 at 23:24
  • I updated the question with the complete code until the point it breaks, the problem is on the if statement. – Lalo Santos Apr 27 '17 at 23:26
  • You have no quotes on port `$port = port;` – Barry Thomas Apr 27 '17 at 23:39
  • @BarryThomas I just put the word port there to not include the actual value, but it is written correctly in my code. – Lalo Santos Apr 27 '17 at 23:40
  • I'm not sure so, but I tried this `$gbst = "OFF"; $siostate = "Run"; $siorunning = "No"; $ssqlrunning = "No"; if ($gbst === "OFF" || $siostate !== "Running" || $siorunning !== "Yes" || $ssqlrunning !== "Yes") { echo "Hello"; }else{ echo "Goodbye"; }` and it works for me. – Barry Thomas Apr 27 '17 at 23:51
  • I was under the impression PHP doesn't really mind about spaces, but what I did is I removed a blank space that existed after each double pipe (||) and that did the trick. I'm unsure as to what happened here. Im skeptical to believe it had something to do with a special character, since I wrote the code myself (not any copy paste). – Lalo Santos Apr 28 '17 at 01:38

0 Answers0