Skip to content

Commit ee98320

Browse files
committed
Releasing 0.9.2
2 parents 250a91c + 5914b95 commit ee98320

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/TgDatabase/DAO.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ public function delete($object) {
192192
return FALSE;
193193
}
194194

195+
196+
/**
197+
* Delete the objects using the given criteria.
198+
* @param array $criteria - the criterions to match for delete for (AND) - see README.md (optional, default will clear table)
199+
* @return mixed - FALSE when delete failed, TRUE when successful
200+
*/
201+
public function deleteBy($criteria = array()) {
202+
$whereClause = $this->createWhereClause($criteria);
203+
$query = 'DELETE FROM '.$this->database->quoteName($this->tableName).' '.$whereClause;
204+
return $this->database->query($query);
205+
}
206+
195207
/**
196208
* Get the full SQL query to delete the given uid.
197209
* <p>Override this to implement soft delete functionality.</p>

src/TgDatabase/Database.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
class Database {
1111

1212
/** The database config */
13-
protected $dbconfig;
13+
protected $config;
1414
/** The database connection */
1515
public $con;
1616

1717
/**
1818
* Constructor.
19-
* @param array $dbconfig - configuration array (see README.md)
19+
* @param array $config - configuration array (see README.md)
2020
* @param \TgUtils\Auth\CredentialsProvider $provider - provider for credentials from an external source (optional)
2121
*/
22-
public function __construct($dbconfig, \TgUtils\Auth\CredentialsProvider $provider = NULL) {
23-
$this->dbconfig = $dbconfig;
22+
public function __construct($config, \TgUtils\Auth\CredentialsProvider $provider = NULL) {
23+
$this->config = $config;
2424
$this->connect($provider);
2525
}
2626

@@ -36,15 +36,15 @@ protected function connect(\TgUtils\Auth\CredentialsProvider $provider = NULL) {
3636
$username = $provider->getUsername();
3737
$password = $provider->getPassword();
3838
} else {
39-
$username = $this->dbconfig['user'];
40-
$password = $this->dbconfig['pass'];
39+
$username = $this->config['user'];
40+
$password = $this->config['pass'];
4141
}
4242
$this->con = new \mysqli(
43-
$this->dbconfig['host'],
43+
$this->config['host'],
4444
$username,
4545
$password,
46-
$this->dbconfig['dbname'],
47-
$this->dbconfig['port']
46+
$this->config['dbname'],
47+
$this->config['port']
4848
);
4949
if ($this->con->connect_errno) {
5050
error_log('Failed to connect to MySQL: '.$this->con->connect_errno);
@@ -291,8 +291,8 @@ public function updateSingle($table, $fields, $where) {
291291
* @param string $s - the table name
292292
* @param string the table name with prefix replaced
293293
*/
294-
protected function replaceTablePrefix($s) {
295-
$prefix = $this->dbconfig['tablePrefix'];
294+
public function replaceTablePrefix($s) {
295+
$prefix = $this->config['tablePrefix'];
296296
if (!$prefix) $prefix = '';
297297
return str_replace('#__', $prefix, $s);
298298
}

0 commit comments

Comments
 (0)