I can't work out why the below 'check if mysql table exists function' is no longer working having upgraded my php version to 7.2
It now always returns false/an empty array, even when the table exists.
I have tried checking throughout whether the variables are defined & manually outputting their (string) values at each stage. When I do so I get the expected result (i.e. row/s returned) - but I don't seem to be able to bind them.
public function tableExists($name) {
// Try a select statement against the table
// Run it in try/catch in case PDO is in ERRMODE_EXCEPTION.
$dbname = $this->DB_NAME;
try {
$result = $this->select("SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = :DB_NAME AND table_name = :name", array(':DB_NAME' => $dbname, ':name' => $name));
} catch (Exception $e) {
// We got an exception == table not found
$result = FALSE; //$e->getMessage();
}
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
return $result;
}
My select function below definitely receives the correct values so I must be binding them in a way that no longer works in php7.2.
I've also tried bindParam
instead of bindValue
in the hope that might work, but to no avail.
/*
*Select
*@param string $sql - An SQL string
*@param array $array - An array of parameters to bind. Default is empty array
*@param constant $fetchMode - A PDO fetchmode. Default is fetch_assoc
*return mixed
*/
public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC) {
$sth = $this->prepare($sql);
foreach ($array as $key => $value) {
if($value == (int)$value)
$sth->bindValue("$key", $value, PDO::PARAM_INT);
else
$sth->bindValue("$key", $value);
}
$sth->execute();
$this->rowCount = $sth->rowCount();
return $sth->fetchAll($fetchMode);
}
Any help much appreciated!
I thought this would help - but it didn't: PDO Statement does not work anymore in PHP 7