到目前为止,我就是这样:
我不确定为什么Hakre关闭它,因为它与从MySQL事件调度程序中删除MySQL事件而不是使用PDO使用表名。
我的代码如下:
public function dMySQLEvent($my_env, $my_event_name) {
$my_success = 0;
$my_message = '';
try {
# declare & set variables using $my_env
list ($db_dbdriver, $db_hostname, $db_database, $db_username, $db_password) = Connection::dbConnect($my_env);
# set default timezone
# create & set connection
# WORKS
# $conn->exec("DROP EVENT IF EXISTS " . $my_event_name . ";");
# DOES NOT WORK
# Prepare an SQL statement
$my_sql = "DROP EVENT IF EXISTS :My_Event_Name";
$stmt = $conn->prepare($my_sql);
# bind parameters to prevent SQL Injection
$stmt->bindValue(':My_Event_Name', $my_event_name);
# execute the SQL statement
$stmt->execute();
# closes the cursor, enabling the statement to be executed again
$stmt->closeCursor();
# close & unset the connection
$stmt = null;
unset($stmt);
$conn = null;
unset($conn);
# Set success value to TRUE
$my_success = 1;
$my_message = 'success';
} catch(PDOException $e) {
# Append error message to error log
}
return array($my_success, $my_message);
}