public function testIsAssociative() { $a = ["test1", "test2", "test3"]; $this->assertFalse(ArrayHelper::isAssociative($a)); $a = ["k1" => "test1", "k2" => "test2", "k3" => "test3"]; $this->assertTrue(ArrayHelper::isAssociative($a)); }
/** * Executes a prepared statement * * @param array|null $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as PDO::PARAM_STR. * @return bool Returns TRUE on success or FALSE on failure. */ public function execute($input_parameters = null) { if ($this->_statement === null) { $queryString = $this->_queryString; // Extract Operators from input parameters and add to operators (removing from input parameters as well) if (is_array($input_parameters)) { $input_parameters_without_operators = []; foreach ($input_parameters as $pName => $pVal) { if ($pVal instanceof Operator) { $pVal->setParameterName($pName); $this->_operators[$pName] = $pVal; } else { $input_parameters_without_operators[$pName] = $pVal; } } $input_parameters = $input_parameters_without_operators; } // queryString parsing for setting operators parameters foreach ($this->_operators as $oName => $oVal) { if (substr_count($queryString, $oName) == 0) { throw new MissingPlaceholder("Missing placeholder for operator {$oName} in query string {$queryString}"); } if (substr_count($queryString, $oName) > 1) { throw new InvalidPlaceholder("Invalid placeholder for operator {$oName} in query string {$queryString}. It's referenced more thant once."); } $queryString = str_replace($oName, $oVal->getQueryStringPart(), $queryString); } // Prepare original PDOStatement $driver_options = is_null($this->_driverOptions) ? [] : $this->_driverOptions; $driver_options[] = PDO::USE_ORIGINAL_PDO_STATEMENT; $s = $this->_parent->prepare($queryString, $driver_options); if ($s === false) { return false; } $this->_statement = $s; // Setting parameters returned by operators foreach ($this->_operators as $oName => $oVal) { foreach ($oVal->getParameters() as $pName => $pVal) { if ($pVal instanceof DataTypes\DataType) { $this->_statement->bindValue($pName, $pVal->getPgsqlValue()); } else { $this->_statement->bindValue($pName, $pVal); } } } } if (is_null($input_parameters)) { foreach ($this->_parameters as $p) { $this->_statement->bindValue($p->getParameterName(), $p->getPgsqlValue()); } foreach ($this->_pdoOriginalParameters as $p => $pVal) { $this->_statement->bindParam($pVal[0], $pVal[1], $pVal[2], $pVal[3], $pVal[4]); } } else { $isPositional = !Helpers\ArrayHelper::isAssociative($input_parameters); foreach ($input_parameters as $pName => $pVal) { if ($isPositional) { $pName = $pName + 1; } // See Issue #5: if input_parameters isn't an associative array // pName contains the array index if ($pVal instanceof DataTypes\DataType) { $this->_statement->bindValue($pName, $pVal->getPgsqlValue()); } else { $this->_statement->bindValue($pName, $pVal); } } } $r = $this->_statement->execute(); $this->_executed = $r; return $r; }