Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 135 lines (112 sloc) 2.356 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
<?php
require_once 'SQLComposer.class.php';

/**
* SQLComposerDelete
*
* A DELETE query
*
* @package SQLComposer
* @author Shane Smith
*/
class SQLComposerDelete extends SQLComposerWhere {

/**
* DELETE FROM
*
* @var array
*/
protected $delete_from = array( );

/**
* IGNORE
*
* @var bool
*/
protected $ignore = false;

/**
* ORDER BY
*
* @var array
*/
protected $order_by = array( );

/**
* LIMIT
*
* @var int
*/
protected $limit = null;


/*******************
** CONSTRUCTOR **
*******************/

/**
* Constructor.
*
* @param string $table
*/
public function __construct($table=null) {
if (isset($table)) $this->delete_from($table);
}

/**
* Add a table to the DELETE FROM clause
*
* @param string|array $table
* @return SQLComposerDelete
*/
public function delete_from($table) {
$this->delete_from = array_merge($this->delete_from, (array)$table);
return $this;
}

/**
* Add a table to the USING clause
*
* @param string|array $table
* @param array $params
* @param string $mysqli_types
* @return SQLComposerDelete
*/
public function using($table, array $params = null, $mysqli_types = "") {
return $this->add_table($table, $params, $mysqli_types);
}

/**
* ORDER BY
*
* @param string|array $order_by
* @return SQLComposerDelete
*/
public function order_by($order_by) {
$this->order_by = array_merge($this->order_by, (array)$order_by);
return $this;
}

/**
* LIMIT
*
* @param int $limit
* @return SQLComposerDelete
*/
public function limit($limit) {
$this->limit = $limit;
return $this;
}


/*****************
** RENDERING **
*****************/

/**
* Render the SQL query
*
* @return string
*/
public function render() {

$delete_from = implode(", ", $this->delete_from);

$using = empty($this->tables) ? "" : "\nUSING " . implode("\n\t", $this->tables);

$where = $this->_render_where();

$order_by = empty($this->order_by) ? "" : "\nORDER BY " . implode(", ", $this->order_by);

$limit = !isset($this->limit) ? "" : "\nLIMIT " . $this->limit;

return "DELETE FROM {$delete_from} {$using} \nWHERE {$where} {$order_by} {$limit}";
}

/**
* Get the parameters
*
* @return array
*/
public function getParams() {
return $this->_get_params('tables', 'using', 'where');
}

}
Something went wrong with that request. Please try again.