Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // db connection
- $dsn = 'mysql:host=localhost;dbname=testmysql';
- $username = 'test';
- $password = 'test';
- $options = array(
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
- );
- $dbConn = new PDO($dsn, $username, $password, $options);
- $dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $id = 2;
- $txtColData = 'text '. uniqid();
- $sql = "UPDATE `Table1`
- SET `txt'` = ?
- WHERE `id` = ?";
- $stmt = $dbConn->prepare($sql);
- $allOk = $stmt->execute(array($txtColData, $id));
- var_dump($allOk);
- // show result
- $stmt = $dbConn->prepare("select * from `table1`");
- $allOk = $stmt->execute();
- $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
- var_dump($allOk, $result);
- exit;
- // -------------------------------------------------------------------------
- // Sample table and data
- /*
- DROP TABLE IF EXISTS `table1`;
- CREATE TABLE `table1` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `foo` varchar(63) COLLATE utf8_unicode_ci NOT NULL,
- `bar` varchar(63) COLLATE utf8_unicode_ci NOT NULL,
- `txt'` varchar(63) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Contains a quote as part of the name',
- UNIQUE KEY `xxx` (`foo`),
- KEY `id` (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
- *
- */
- /*Data for the table `table1` */
- /*
- insert into `table1`(`id`,`foo`,`bar`,`txt'`) values (1,'foo1','bar1','txt1');
- insert into `table1`(`id`,`foo`,`bar`,`txt'`) values (2,'foo2','bar1','text 3');
- insert into `table1`(`id`,`foo`,`bar`,`txt'`) values (3,'foo3','bar1',NULL);
- insert into `table1`(`id`,`foo`,`bar`,`txt'`) values (4,'foo4','bar1',NULL);
- insert into `table1`(`id`,`foo`,`bar`,`txt'`) values (5,'foo5','bar1',NULL);
- *
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement