Skip to content

Instantly share code, notes, and snippets.

@johanot
Created January 5, 2013 15:23
Show Gist options
  • Select an option

  • Save johanot/4462078 to your computer and use it in GitHub Desktop.

Select an option

Save johanot/4462078 to your computer and use it in GitHub Desktop.
Hello World
<?php
require_once('db/DBConnection.php');
require_once('db/DBStatement.php');
require_once('db/DBParameter.php');
require_once('db/DBException.php');
class DBLog
{
private $conn;
private $outboundId;
public function DBLog() {
$this->conn = DBConnection::getConnection(SMS_DBHOST, SMS_DBUSER, SMS_DBPASS, SMS_DBNAME);
$this->autocommit(false);
}
public function logOutboundSMS(SMS $s) {
$stmt = new DBStatement("INSERT INTO sms_outbound (time_sent, inboundid, to_number, price, message, lac, audit_name, ddsAccount) VALUES (?time_sent?, ?inboundid?, ?to_number?, ?price?, ?message?, ?lac?, ?audit_name?, ?ddsaccount?)", $this->conn);
$stmt->addParameter(DBParameter::create('time_sent', date("Y-m-d H:i:s")));
$stmt->addParameter(DBParameter::create('inboundid', isset($s->inboundid) ? $s->inboundid : null));
$stmt->addParameter(DBParameter::create('to_number', implode(',', $s->to)));
$stmt->addParameter(DBParameter::create('price', $s->price));
$stmt->addParameter(DBParameter::create('message', $s->message));
$stmt->addParameter(DBParameter::create('lac', $s->lac));
$stmt->addParameter(DBParameter::create('audit_name', $s->audit_name));
$stmt->addParameter(DBParameter::create('ddsaccount', $s->ddsaccount));
$stmt->execute();
if ($this->conn->errno != 0)
throw new DBException("(DBLog) Could not log outbound SMS - mysql says: ". $this->conn->error, longval($this->conn->errorno));
$this->outboundId = $stmt->insert_id;
}
public function setGatewayStatus($status) {
$stmt = new DBStatement("UPDATE sms_outbound SET gateway_status = ?gateway_status? WHERE sms_outbound_id = ?sms_outbound_id?", $this->conn);
$stmt->addParameter(DBParameter::create('gateway_status', $status));
$stmt->addParameter(DBParameter::create('sms_outbound_id', $this->outboundId));
$stmt->execute();
if ($this->conn->errno != 0)
log_error("Could not log gateway status :( ". $status. " - outboundId: ". $this->outboundId);
}
public function commit() {
$this->conn->commit();
}
public function rollback() {
$this->conn->rollback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment