/** * @covers SQLBuilder::getParamTypes */ public function testGetParamTypes() { $condition = "id in ? OR email like ?"; $this->sql->filter($condition, 'as', array(1, 2), 'fr'); $params = $this->sql->getParamTypes(); $this->assertEquals('iis', $params); }
/** * Prepare the given query for execution. * * @param SQLBuilder|String $sql can be either: * a. SQLBuilder: in which case it may contain parameters prepared * statements. * b. String: Plain SQL. * @param PagingInfo $paging * @return mysqli_stmt * @throws */ public function prepare($sql, $paging = null) { if (!$sql) { throw new SQLException("Empty query"); } # Keep the PagingInfo so we can set total rows later on. $this->paging = $paging; $queryPager = new QueryPager($sql, $paging); if ($this->debugOn) { Logger::debug("SQL: {$sql}"); } # Create a prepared statement $stmt = $this->db->prepare($queryPager->getQuery()); if (!$stmt) { throw new SQLException($this->db->error); } # Bind parameters, if there are any if ($sql instanceof SQLBuilder && $sql->hasParams()) { $refArgs = array($sql->getParamTypes()); foreach ($sql->getParamList() as $param) { $refArgs[] = $param; } // Modify the values in the array to be referenced (ugly, but works). for ($i = 1; $i < count($refArgs); $i++) { $refArgs[$i] =& $refArgs[$i]; } call_user_func_array(array($stmt, 'bind_param'), $refArgs); if ($this->debugOn) { Logger::debug("Query params: " . var_export($refArgs, true)); } } return $stmt; }