Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $execute($ddl_partial);
- $execute($insert);
- $execute($ddl_full);
- $execute($insert);
- $execute($drop);
- $execute($ddl_partial);
- $execute($insert);
- array(4) {
- [0] =>
- string(5) "00000"
- [1] =>
- int(0)
- [2] =>
- string(24) " ((null)[0] at (null):0)"
- [3] =>
- string(0) ""
- }
- <?php
- $hostname = 'microsoftsql.example.com';
- $database = 'mydb';
- $username = 'user';
- $password = 'P@55w0rd';
- // https://www.microsoft.com/en-us/download/details.aspx?id=50419
- $driver = 'ODBC Driver 13 for SQL Server';
- $pdo = new PDO("odbc:Driver=$driver;
- Server=$hostname;
- Database=$database",
- $username,
- $password
- );
- $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
- $pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
- $drop = "DROP TABLE testerino;";
- $ddl_full = "
- CREATE TABLE testerino (
- value VARCHAR(10),
- other VARCHAR(10)
- );
- ";
- $ddl_partial = "
- CREATE TABLE testerino (
- value VARCHAR(10)
- );
- ";
- $insert = "
- INSERT INTO testerino (value)
- VALUES ('first');
- INSERT INTO testerino (value, other)
- VALUES ('second', 'another');
- INSERT INTO testerino (value)
- VALUES ('third');
- ";
- $execute = function (String $sql) use ($pdo) {
- $pdo->beginTransaction();
- try {
- $statement = $pdo->prepare($sql);
- $statement->execute();
- do {
- /* https://bugs.php.net/bug.php?id=61613 */
- var_dump($statement->errorInfo());
- }
- while ($statement->nextRowset());
- $pdo->commit();
- } catch (PDOException $e) {
- $pdo->rollBack();
- throw $e;
- } finally {
- $statement->closeCursor();
- }
- };
- $execute($drop); // not needed first time
- $execute($ddl_full);
- $execute($insert);
- $execute($drop);
- $execute($ddl_partial);
- $execute($insert);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement