Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- /*
- * Configuration
- */
- $dbname = '';
- $username = '';
- $password = '';
- /* list of tables to drop */
- $tables = ['table1', 'table2', 'table3'];
- $eol = empty($argc) ? '<br>' : PHP_EOL; // determine end of line
- /*
- * Connect to database and attempt to drop tables
- */
- $dbc = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
- foreach ($tables as $table) {
- try {
- /* format DROP statement */
- $sql = 'DROP TABLE ' . $table;
- echo $eol, $sql, $eol;
- /* execute statement */
- $dbc->exec($sql);
- /* SQLSTATE should be '00000' */
- $info = $dbc->errorInfo();
- if ($info[0] === PDO::ERR_NONE) {
- $info[2] = 'Command successful';
- }
- echo sprintf('SQLSTATE[%s]: %s', $info[0], $info[2]), $eol;
- } catch (PDOException $e) {
- echo $e->getMessage(), $eol;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment