Link.FYI

Pastebin

Create New My Pastes

Code (PHP) pasted on 2019-01-26, 19:52 Raw Source

  1. <?php
  2.  
  3.     $db->exec("
  4.      CREATE TABLE IF NOT EXISTS account (
  5.        name TEXT PRIMARY KEY
  6.      );
  7.    ");
  8.  
  9.     $db->exec("
  10.      CREATE TABLE IF NOT EXISTS recipientpayer (
  11.        name TEXT PRIMARY KEY
  12.      );
  13.    ");
  14.  
  15.     $db->exec("
  16.      CREATE TABLE IF NOT EXISTS payment (
  17.        hash TEXT,
  18.        account INTEGER,
  19.        recipientpayer INTEGER,
  20.        subject TEXT,
  21.        date NUMERIC,
  22.        amount NUMERIC,
  23.        type TEXT,
  24.        FOREIGN KEY(account) REFERENCES account(ROWID) ON UPDATE CASCADE ON DELETE RESTRICT,
  25.        FOREIGN KEY(recipientpayer) REFERENCES recipientpayer(ROWID) ON UPDATE CASCADE ON DELETE RESTRICT
  26.      );
  27.      CREATE INDEX IF NOT EXISTS idx_payment_hash ON payment(hash);
  28.      CREATE INDEX IF NOT EXISTS idx_payment_amount ON payment(date, amount);
  29.      CREATE INDEX IF NOT EXISTS idx_payment_subject ON payment(date, subject);
  30.    ");
  31.  
  32. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33.  
  34.  try {
  35.          
  36.             $stmt = $this->db->prepare("
  37.          INSERT INTO payment (
  38.            hash, account, recipientpayer, subject, date, amount, type
  39.          ) VALUES (
  40.            ?, ?, ?, ?, ?, ?, ?
  41.          )
  42.        ");
  43.  
  44.             $stmt->execute([
  45.                 $payment->getHash(),
  46.                 $this->getAccountID($payment->getAccount()),
  47.                 $this->getRecipientPayerID($payment->getRecipientPayer()),
  48.                 $payment->getText(),
  49.                 $payment->getDate(),
  50.                 $payment->getAmount(),
  51.                 $payment->getType()
  52.             ]);
  53.             return $this->getPaymentID($payment->getHash());
  54.  
  55.         } catch (PDOException $e) {
  56.         }
  57.  
  58. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59.  
  60.  
  61.