Skip to content

Commit

Permalink
Bug fixed related to table prefix in join methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
izniburak committed Dec 15, 2018
1 parent d30f025 commit 4b7c6e4
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/Pdox.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(array $config)
$this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
$this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
} catch (PDOException $e) {
die('Cannot the connect to Database with PDO.<br /><br />' . $e->getMessage());
die('Cannot the connect to Database with PDO. ' . $e->getMessage());
}

return $this->pdo;
Expand All @@ -80,23 +80,20 @@ public function __construct(array $config)
public function table($table)
{
if (is_array($table)) {
$froms = '';
$from = '';
foreach ($table as $key) {
$froms .= $this->prefix . $key . ', ';
$from .= $this->prefix . $key . ', ';
}

$this->from = rtrim($froms, ', ');
$this->from = rtrim($from, ', ');
} else {
// if parameter $table value is 'table1, table2'
// this is a bug!
$istables = strpos($table, ',') > 0;
if ( $istables ){
if (strpos($table, ',') > 0) {
$tables = explode(',', $table);
foreach ($tables as $key => &$value) {
$value = $this->prefix . ltrim($value);
}
$this->from = implode(',', $tables);
}else{
$this->from = implode(', ', $tables);
} else {
$this->from = $this->prefix . $table;
}
}
Expand Down Expand Up @@ -159,8 +156,8 @@ public function join($table, $field1 = null, $op = null, $field2 = null, $type =

if (! is_null($op)) {
$on = (! in_array($op, $this->op) ?
$this->prefix . $field1 . ' = ' . $this->prefix . $op :
$this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
$this->from . '.' . $field1 . ' = ' . $table . '.' . $op :
$this->from . '.' . $field1 . ' ' . $op . ' ' . $table . '.' . $field2);
}

if (is_null($this->join)) {
Expand Down

0 comments on commit 4b7c6e4

Please sign in to comment.