I am trying to write a PHP script to check if a table exists in Firebird, but because I have to use the dollar sign in the SQL, I get an error. Here is the code:
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'\mobile\debug_mob_config.php');
$tableName = 'creadit_check';
// Check if the table exists
$query = "SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$RELATION_NAME = :table_name";
$stmt = $DB->prepare($query);
$stmt->bindParam(':table_name', $tableName);
$stmt->execute();
$tableExists = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$tableExists) {
// Create the table if it doesn't exist
$createTableQuery = "
CREATE TABLE $tableName (
id INTEGER NOT NULL,
name VARCHAR(255),
PRIMARY KEY (id)
)
";
$DB->exec($createTableQuery);
echo "Table '$tableName' created successfully.";
} else {
echo "Table '$tableName' already exists.";
}
I have tried using the backquote to get round this but still get the error.