From 477285c77557abf316591f642030016e82d189e8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 26 Sep 2018 15:51:27 +0200 Subject: [PATCH] create script => no need to database backup --- virtual/vhost/public_html/index.php | 58 ++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/virtual/vhost/public_html/index.php b/virtual/vhost/public_html/index.php index 248d15e..fe3c92d 100644 --- a/virtual/vhost/public_html/index.php +++ b/virtual/vhost/public_html/index.php @@ -1,4 +1,60 @@ setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); + $pdo->setAttribute(PDO::ATTR_TIMEOUT, 5); + $pdo->setAttribute(PDO::ERRMODE_EXCEPTION, true); + $pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + + }catch(Exception $e){ + printf("Cannot connect to database\n"); + die(); + } + + + // 1. Create table + $create = "CREATE TABLE IF NOT EXISTS nonce ( + id_nonce int NOT NULL AUTO_INCREMENT PRIMARY KEY, + created_at int NOT NULL DEFAULT CURRENT_TIMESTAMP + );"; + + if( $errcode = $pdo->exec($create) > 0 ){ + printf("* [%d] cannot create table\n\n", $errcode); + die(); + } + + // 2. Insert new line + + $pr = $pdo->prepare("INSERT INTO nonce(id_nonce, created_at) VALUES(DEFAULT, :tnow);"); + + if( $pr !== false ){ + $ok = $pr->execute([":tnow" => time()]); + if( !$ok ){ + printf("* cannot insert data\n\n"); + } + }else{ + printf("* cannot insert data\n\n"); + } + + // 3. select all + $st = $pdo->query("SELECT * FROM nonce ORDER BY id_nonce;"); + if( $st !== false ){ + + $nonces = $st->fetchAll(); + printf("
\n");
+		foreach( $nonces as $key=>$value ){
+			printf("[%d] nonce id %s created at %s\n", $key, $value['id_nonce'], date('H:i:s d/m/Y', $value['created_at']));
+		}
+		printf("
\n"); + + }else{ + printf("* cannot fetch data\n\n"); + } + + + + echo "my app"; \ No newline at end of file