/** * Executes a prepared statement * * Execute the prepared statement. If the prepared statement included parameter markers, you must either: * * call PDOStatement::bindParam() to bind PHP variables to the parameter markers: bound variables pass * their value as input and receive the output value, if any, of their associated parameter markers * or pass an array of input-only parameter values * * * @param array|null $inputParameters - 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. (not yet implemented because of a bug in vitess) * * You cannot bind multiple values to a single parameter; for example, * you cannot bind two values to a single named parameter in an IN() clause. * * You cannot bind more values than specified; if more keys exist * in input_parameters than in the SQL specified in the PDO::prepare(), * then the statement will fail and an error is emitted. * @return bool * @throws PDOException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(array $inputParameters = null) { $this->reset(); if ($inputParameters) { if (array_key_exists(0, $inputParameters)) { $inputParameters = $this->repairUnnamedParamsArray($inputParameters); } foreach ($inputParameters as $key => $value) { $this->bindValue($key, $value); // default type is string } } $vitessMethod = 'executeRead'; $query = $this->queryAnalyzer->parseQuery($this->query); if ($query->isWritable()) { $vitessMethod = 'executeWrite'; } try { /* @var $result ResultInterface */ $result = $this->executor->{$vitessMethod}($query, $this->params); $this->setResult($result); if (!$result->isSuccess()) { return false; } $this->cursor = new Cursor($result->getCursor(), $this->fetcherFactory); } catch (CoreException $e) { $this->setResult(new PDO\Vitess\Result(null, $e)); if ($e instanceof PDOException && $this->attributes->isErrorModeException()) { throw $e; } return false; } return true; }
/** * Execute an SQL statement and return the number of affected rows * * PDO::exec() executes an SQL statement in a single function call, returning the number of rows affected * by the statement. * * PDO::exec() does not return results from a SELECT statement. For a SELECT statement that you only need to issue * once during your program, consider issuing PDO::query(). For a statement that you need to issue multiple times, * prepare a PDOStatement object with PDO::prepare() and issue the statement with PDOStatement::execute(). * * @param string $statement - The SQL statement to prepare and execute. * Data inside the query should be properly escaped. * * @return int - PDO::exec() returns the number of rows that were modified or deleted by the SQL statement * you issued. If no rows were affected, PDO::exec() returns 0. */ public function exec($statement) { $query = $this->queryAnalyzer->parseQuery($statement); $this->lastResult = $this->executor->executeWrite($query); if (!$this->lastResult->isSuccess()) { return false; } $cursor = $this->lastResult->getCursor(); return $cursor->getRowsAffected(); }