123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- class DBPagopar extends PDO{
-
- public function __construct($name=null,$user=null,$pass=null) {
-
- parent::__construct('mysql:host=localhost;dbname='.$name,$user,$pass,
- [PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
-
- $this->exec("CREATE TABLE IF NOT EXISTS transactions(
- id integer primary key,
- typeOrder varchar(120),
- totalAmount decimal(15,2),
- hash varchar(255),
- maxDateForPayment varchar(120),
- buyerId integer,
- orderItems integer,
- description varchar(255),
- created datetime default current_timestamp
- )");
- }
-
- public function insertTransaction($id,$typeOrder,$totalAmount,$hash,$maxDateForPayment,$desc) {
- $this->prepare("INSERT INTO transactions (id,typeOrder,totalAmount,hash,maxDateForPayment,description) VALUES(?,?,?,?,?,?)")
- ->execute([$id,$typeOrder,$totalAmount,$hash,$maxDateForPayment,$desc]);
- return $this->lastInsertId();
- }
-
- public function selectTransaction($where = '') {
- $sth = $this->prepare("SELECT * FROM transactions WHERE {$where} LIMIT 1");
- $sth->execute();
- $result = $sth->fetchAll();
- if (empty($result)) {
- return false;
- }
- return $result[0];
- }
-
- public function updateTransaction(Array $data, Array $w) {
- $set = array();
- foreach (array_keys($data) as $key) {
- $set[] = "$key = :$key";
- }
- $where = array();
- foreach (array_keys($w) as $key) {
- $where[] = "$key = :$key";
- }
- $this->prepare("UPDATE transactions SET " . implode(",", $set)
- . " where " . implode(" and ", $where) )
- ->execute(array_merge($data, $w));
- }
- }
|