ALTER TABLE with PDO and parameters?

Is it possible to add parameters using ALTER TABLEPDO.

I tried,

$q = $dbc -> prepare("ALTER TABLE emblems ADD ? TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', ADD ? DATETIME NOT NULL");
$q -> execute(array($emblemDB, $emblemDB . 'Date'));

But that failed.

Thank.

+5
source share
1 answer

The nature of the alternative table queries, as far as I know, are not prepared statements. But you have to call the function beginTransactionand commit()for the majority of queries, changing table.

$dbh->beginTransaction();

/* Change the database schema and data */
$sth = $dbh->exec("DROP TABLE fruit");
$sth = $dbh->exec("UPDATE dessert
SET name = 'hamburger'");
$sth = $dbh->exec("ALTER TABLE `dessert` ADD `field1` VARCHAR(24) NOT NULL");


/* Commit changes */
$dbh->commit();

Although you can use the prepared notes and perform as far as I know.

Note:
MySQL implicitly calls the commit () function in queries CREATE TABLEand DROP TABLEtherefore rollback is not possible.

, alter table, , ( ) db, PDO inout. , .

0

All Articles