maximebf / atomik

Micro framework for PHP 5.3+ [UNMAINTAINED]
MIT License
46 stars 18 forks source link

Allow multiples values for a single key in _buildWhere() #31

Closed zessx closed 10 years ago

zessx commented 10 years ago

Allow user to set multiples values for a single key.

Examples :

$posts = $this['db']->select('articles', '*', array('year' => array(2014, 2015)));

Tests :

Empty string : _buildWhere()

array(2) {
  [0]=>
  string(0) ""
  [1]=>
  array(0) {
  }
}

No parameters : _buildWhere('year = 2014')

array(2) {
  [0]=>
  string(17) "WHERE year = 2014"
  [1]=>
  array(0) {
  }
}

Bind an integer : _buildWhere(array('year' => 2014))

array(2) {
  [0]=>
  string(14) "WHERE year = ?"
  [1]=>
  array(1) {
    [0]=>
    int(2014)
  }
}

Bind a string : _buildWhere(array('year' => '2014'))

array(2) {
  [0]=>
  string(14) "WHERE year = ?"
  [1]=>
  array(1) {
    [0]=>
    string(4) "2014"
  }
}

Bind an array : _buildWhere(array('year' => array('2014', '2015')))

array(2) {
  [0]=>
  string(19) "WHERE year IN(?, ?)"
  [1]=>
  array(2) {
    [0]=>
    string(4) "2014"
    [1]=>
    string(4) "2015"
  }
}

Bind a string plus an array : _buildWhere(array('year' => '2014', 'month' => array('jan', 'fev')))

array(2) {
  [0]=>
  string(33) "WHERE year = ? AND month IN(?, ?)"
  [1]=>
  array(3) {
    [0]=>
    string(4) "2014"
    [1]=>
    string(3) "jan"
    [2]=>
    string(3) "fev"
  }
}

Bind an array plus a string : _buildWhere(array('year' => array('2014', '2015'), 'month' => 'jan'))

array(2) {
  [0]=>
  string(33) "WHERE year IN(?, ?) AND month = ?"
  [1]=>
  array(3) {
    [0]=>
    string(4) "2014"
    [1]=>
    string(4) "2015"
    [2]=>
    string(3) "jan"
  }
}

Bind two arrays : _buildWhere(array('year' => array('2014', '2015'), 'month' => array('jan', 'fev')))

array(2) {
  [0]=>
  string(38) "WHERE year IN(?, ?) AND month IN(?, ?)"
  [1]=>
  array(4) {
    [0]=>
    string(4) "2014"
    [1]=>
    string(4) "2015"
    [2]=>
    string(3) "jan"
    [3]=>
    string(3) "fev"
  }
}
maximebf commented 10 years ago

you have a forgotten var_dump() at line 202. please replace array_push at line 217 with $values[] = $value.

zessx commented 10 years ago

Sorry for this forgotten var_dump(). Any reason to prefer $values[] = $value over array_push($values, $value) ?