Created
July 20, 2019 13:07
-
-
Save alexalannunes/6eff79c8f88e10bbc632aacf235e823a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors',1); | |
ini_set('display_startup_erros',1); | |
error_reporting(E_ALL); | |
try { | |
$pdo = new PDO('pgsql:host=localhost;dbname=postgres', 'postgres', 'a0l11e4x23'); | |
} | |
catch (PDOException $e) { | |
print "Erro: " . $e->getMessage() . "<br/>"; | |
die(); | |
} | |
$md5 = md5(time()); | |
try | |
{ | |
$pdo->beginTransaction(); | |
$q = $pdo->prepare("INSERT INTO users(name, uid) VALUES('alex', :md5)"); | |
$q->bindParam(':md5', $md5); | |
$q->execute(); | |
if ($q->rowCount()) | |
{ | |
echo "INCOME\n"; | |
$inc = $pdo->prepare("INSERT INTO incomes(name, uid) VALUES('me', :md5)"); | |
$inc->bindParam(':md5', $md5); | |
$inc->execute(); | |
} | |
else | |
{ | |
$pdo->rollBack(); | |
} | |
if ($q->rowCount()) | |
{ | |
echo "EXP\n"; | |
$exp = $pdo->prepare("INSERT INTO expenses(uid, name) VALUES(:md5, 'me')"); | |
$exp->bindParam(':md5', $md5); | |
$exp->execute(); | |
} | |
else | |
{ | |
$pdo->rollBack(); | |
} | |
$pdo->commit(); | |
} | |
catch (PDOException $e) | |
{ | |
echo $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment