Skip to content

Commit 2bfea28

Browse files
committed
Merge pull request #310 from avbdr/master
Support join in delete()
2 parents dce7544 + 525dc21 commit 2bfea28

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

MysqliDb.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ public function connect()
210210
if (empty ($this->host))
211211
die ('Mysql host is not set');
212212

213-
$this->_mysqli = new mysqli ($this->host, $this->username, $this->password, $this->db, $this->port)
214-
or die('There was a problem connecting to the database');
213+
$this->_mysqli = new mysqli ($this->host, $this->username, $this->password, $this->db, $this->port);
214+
if ($this->_mysqli->connect_error)
215+
throw new Exception ('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error);
215216

216217
if ($this->charset)
217218
$this->_mysqli->set_charset ($this->charset);
@@ -607,7 +608,11 @@ public function delete($tableName, $numRows = null)
607608
if ($this->isSubQuery)
608609
return;
609610

610-
$this->_query = "DELETE FROM " . self::$prefix . $tableName;
611+
$table = self::$prefix . $tableName;
612+
if (count ($this->_join))
613+
$this->_query = "DELETE " . preg_replace ('/.* (.*)/', '$1', $table) . " FROM " . $table;
614+
else
615+
$this->_query = "DELETE FROM " . $table;
611616

612617
$stmt = $this->_buildQuery($numRows);
613618
$stmt->execute();

0 commit comments

Comments
 (0)