Creates a PDOStatment using the string. Loops through param array, and binds each value.
Executes and returns the prepared statement.
@return PDOStatement
332161
function bindAndExecute() {
		$conn = $this->connection;

		if ($conn === null) {
			throw new RuntimeException('bindAndExecute cannot be called on a QueryStatement without a connection.');
		}
		if ($conn instanceof DBMSSQL && $conn->getDriver() === 'dblib' && function_exists('mb_detect_encoding')) {
			return $conn->query($this->__toString());
		}
		if ($conn instanceof DBSQLite) {
			return $conn->query($this->__toString());
		}

		$string = self::embedIdentifiers($this->getString(), array_values($this->identifiers), $conn);

		$result = $conn->prepare($string);
		foreach ($this->getParams() as $key => $value) {
			$pdo_type = PDO::PARAM_STR;
			if (is_int($value)) {
				$pdo_type = PDO::PARAM_INT;
			} elseif (is_null($value)) {
				$pdo_type = PDO::PARAM_NULL;
			} elseif (is_bool($value)) {
				$value = $value ? 1 : 0;
				$pdo_type = PDO::PARAM_INT;
			}
			$result->bindValue($key + 1, $value, $pdo_type);
		}
		$result->execute();
		return $result;
	}
300634
public function prepare($statement, $driverOpts = null) {
		if ($driverOpts === null) {
			$driverOpts = [];
		}

		try {
			$stmt = $this->pdo->prepare($statement, $driverOpts);
			return new PreparedStatement($stmt, $this->pdo, $this->exceptionAdapter);
		} catch (PDOException $e) {
			throw $this->exceptionAdapter->adapt($e, $statement);
		}
	}
349250
protected function bindParam($bind)
    {
        foreach ($bind as $key => $val) {
            $param = is_numeric($key) ? $key + 1 : ':' . $key;

            if (is_array($val)) {
                array_unshift($val, $param);
                $result = call_user_func_array([$this->PDOStatement, 'bindParam'], $val);
            } else {
                $result = $this->PDOStatement->bindValue($param, $val);
            }

            if (!$result) {
                $param = array_shift($val);

                throw new BindParamException(
                    "Error occurred  when binding parameters '{$param}'",
                    $this->config,
                    $this->getLastsql(),
                    $bind
                );
            }
        }
    }
859881
protected function bindValues(\PDOStatement $statement, array $values)
    {
        $number = 1;

        foreach ($values as $name => $value) {
            $this->bindValue($statement, is_string($name) ? $name : $number, $value);
            $number += 1;
        }
    }
1244193
private function getQueryStatement(string $sql): \PDOStatement
    {
        $result = $this->pdo->query($sql);
        if ($result === false) {
            $err = $this->errorInfo();
            throw new \Exception('['.$err[0].']'.$err[2]);
        }
        return $result;
    }
667650
function execute() {
		try {

			// we need to bind in order
			if (empty($this->refactored_stmt)) {
				$index = [];

				$this->refactored_stmt = $this->query;

				# 
				# We need to sort by length to avoid replacing keys that are
				# prefixes of other keys, thereby invaliding the bigger keys
				#

				$keylengths = [];
				foreach (\array_keys($this->params) as $key) {
					$keylengths[$key] = strlen($key);
				}

				\asort($keylengths, SORT_NUMERIC);

				$keys = \array_keys(\array_reverse($keylengths, true));

				foreach ($keys as $key) {
					$position = \strpos($this->query, $key);
					if ($position == false) {
						throw new Panic("Tried to bind parameter $key but it's not present in statement.");
					}

					$this->refactored_stmt = \str_replace($key, '?', $this->refactored_stmt);

					$index[$key] = $position;
				}

				\asort($index, SORT_NUMERIC);

				$this->stmt = \mysqli_prepare($this->dbh, $this->refactored_stmt);

				if ( ! $this->stmt) {
					throw new Panic('Failed to prepare statement');
				}

				$bindings = '';
				$args = [ $this->stmt, null ];
				foreach (array_keys($index) as $key) {
					$bindings .= $this->params[$key][1];
					$args[] = & $this->params[$key][0];
				}

				$args[1] = $bindings;

				if ( ! empty($args[1])) {
					\call_user_func_array('mysqli_stmt_bind_param', $args);
				}
			}
			
			if ( ! \mysqli_stmt_execute($this->stmt)) {
				throw new Panic('Failed to execute statement');
			}

			#
			# to avoid complications with statements not getting closed before
			# new ones are executed we fetch the result set imediatly
			#

			$this->resultset = [];
			$result = \mysqli_stmt_get_result($this->stmt);
			while ($data = mysqli_fetch_assoc($result)) {
				$this->resultset[] = $data;
			}
		}
		catch (\Exception $exception) {
			$message = $exception->getMessage();
			$message .= "\n".$this->formatQuery($this->query);
			throw new Panic($message, 500, $exception);
		}

		return $this;
	}
23134
protected function bindParameter(\PDOStatement $stmt, $params, $types)
    {
        !is_array($params) && $params = array($params);
        !is_array($types) && $types = array($types);

        $isIndex = is_int(key($params));
        $index = 1;

        foreach ($params as $name => $param) {
            // Number index parameters
            if ($isIndex) {
                if (isset($types[$index - 1])) {
                    $stmt->bindValue($index, $param, $types[$index - 1]);
                } else {
                    $stmt->bindValue($index, $param);
                }
                $index++;
            // Named parameters
            } else {
                if (isset($types[$name])) {
                    $stmt->bindValue($name, $param, $types[$name]);
                } else {
                    $stmt->bindValue($name, $param);
                }
            }
        }
    }
1281619
public function bindParameters(PDOStatement $statement, $parameters)
    {
        // Bind all parameters
        $parameterCount = count($parameters);
        for ($index = 0; $index < $parameterCount; $index++) {
            $value = $parameters[$index];
            $phpType = gettype($value);

            // Allow overriding of parameter type using an associative array
            if ($phpType === 'array') {
                $phpType = $value['type'];
                $value = $value['value'];
            }

            // Check type of parameter
            $type = $this->getPDOParamType($phpType);
            if ($type === PDO::PARAM_STR) {
                $value = (string) $value;
            }

            // Bind this value
            $statement->bindValue($index+1, $value, $type);
        }
    }
1262980
public static PreparedStatement bindParams(PreparedStatement pstm, Object... bindValues)
            throws SQLException {
        if (bindValues != null)
            for (int i = 0; i < bindValues.length; i++) {
                Object value = bindValues[i];
                if (value instanceof Boolean) {
                    pstm.setBoolean(i + 1, (Boolean) value);
                } else if (value instanceof Character || value instanceof String) {
                    pstm.setString(i + 1, value.toString());
                } else if (value instanceof Byte) {
                    pstm.setByte(i + 1, (Byte) value);
                } else if (value instanceof Short) {
                    pstm.setShort(i + 1, (Short) value);
                } else if (value instanceof Integer) {
                    pstm.setInt(i + 1, (Integer) value);
                } else if (value instanceof Long) {
                    pstm.setLong(i + 1, (Long) value);
                } else if (value instanceof BigInteger) {
                    pstm.setLong(i + 1, ((BigInteger) value).longValue());
                } else if (value instanceof Float) {
                    pstm.setFloat(i + 1, (Float) value);
                } else if (value instanceof Double) {
                    pstm.setDouble(i + 1, (Double) value);
                } else if (value instanceof BigDecimal) {
                    pstm.setBigDecimal(i + 1, (BigDecimal) value);
                } else if (value instanceof java.sql.Date) {
                    pstm.setDate(i + 1, (java.sql.Date) value);
                } else if (value instanceof java.sql.Time) {
                    pstm.setTime(i + 1, (java.sql.Time) value);
                } else if (value instanceof java.sql.Timestamp) {
                    pstm.setTimestamp(i + 1, (java.sql.Timestamp) value);
                } else if (value instanceof Date) {
                    pstm.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
                } else if (value instanceof Blob) {
                    pstm.setBlob(i + 1, (Blob) value);
                } else if (value instanceof Clob) {
                    pstm.setClob(i + 1, (Clob) value);
                } else if (value instanceof byte[]) {
                    pstm.setBytes(i + 1, (byte[]) value);
                } else {
                    pstm.setObject(i + 1, value);
                }
            }
        return pstm;
    }

    /**
     * Bind parameter values to a {@link CallableStatement}.
     * 
     * @param cstm
     * @param bindValues
     * @return
     * @since 0.8.2
     * @throws SQLException
     */
    public static PreparedStatement bindParams(CallableStatement cstm, Object... bindValues)
            throws SQLException {
        if (bindValues != null)
            for (int i = 0; i < bindValues.length; i++) {
                Object value = bindValues[i];
                if (value instanceof Boolean) {
                    cstm.setBoolean(i + 1, (Boolean) value);
                } else if (value instanceof Character || value instanceof String) {
                    cstm.setString(i + 1, value.toString());
                } else if (value instanceof Byte) {
                    cstm.setByte(i + 1, (Byte) value);
                } else if (value instanceof Short) {
                    cstm.setShort(i + 1, (Short) value);
                } else if (value instanceof Integer) {
                    cstm.setInt(i + 1, (Integer) value);
                } else if (value instanceof Long) {
                    cstm.setLong(i + 1, (Long) value);
                } else if (value instanceof BigInteger) {
                    cstm.setLong(i + 1, ((BigInteger) value).longValue());
                } else if (value instanceof Float) {
                    cstm.setFloat(i + 1, (Float) value);
                } else if (value instanceof Double) {
                    cstm.setDouble(i + 1, (Double) value);
                } else if (value instanceof BigDecimal) {
                    cstm.setBigDecimal(i + 1, (BigDecimal) value);
                } else if (value instanceof java.sql.Date) {
                    cstm.setDate(i + 1, (java.sql.Date) value);
                } else if (value instanceof java.sql.Time) {
                    cstm.setTime(i + 1, (java.sql.Time) value);
                } else if (value instanceof java.sql.Timestamp) {
                    cstm.setTimestamp(i + 1, (java.sql.Timestamp) value);
                } else if (value instanceof Date) {
                    cstm.setTimestamp(i + 1, new Timestamp(((Date) value).getTime()));
                } else if (value instanceof Blob) {
                    cstm.setBlob(i + 1, (Blob) value);
                } else if (value instanceof Clob) {
                    cstm.setClob(i + 1, (Clob) value);
                } else if (value instanceof byte[]) {
                    cstm.setBytes(i + 1, (byte[]) value);
                } else {
                    cstm.setObject(i + 1, value);
                }
            }
        return cstm;
    }
951341
private function _bindPdoParam($array = [])
    {
        // bind array data in pdo
        foreach ($array as $f => $v) {
            // check pass data type for appropriate field
            switch (gettype($array[$f])) {
                // is string found then pdo param as string
                case 'string':
                    $this->STH->bindParam($f + 1, $array[$f], PDO::PARAM_STR);
                    break;
                // if int found then pdo param set as int
                case 'integer':
                    $this->STH->bindParam($f + 1, $array[$f], PDO::PARAM_INT);
                    break;
                // if boolean found then set pdo param as boolean
                case 'boolean':
                    $this->STH->bindParam($f + 1, $array[$f], PDO::PARAM_BOOL);
                    break;
            }
        } // end for each here
    }
716933
protected function prepare($query, $param)
    {
        /**
         * @var \PdoStatement $stmt
         */
        $stmt = $this->db->prepare($query);

        foreach ($param as $set) {
            if (isset($set['value']) || isset($set['name'])) {
                $value = &$set['value'];
                $key   = $set['name'];
            } else {
                $value = &$set[1];
                $key   = $set[0];
            }

            if (!$key) {
                continue;
            }
            $stmt->bindParam($key, $value);
        }

        return $stmt;
    }
57320
public function bind(PDOStatement $pdo_statement, array $data = [])
    {
        foreach ($data as $key => $value) {
            if (is_null($value) || strtolower($value) === 'null') {
                $pdo_statement->bindValue(
                    ':' . $key,
                    $value,
                    PDO::PARAM_NULL
                );
                
                unset($data[$key]);
            }
        }

        foreach ($data as $key => $value) {
            $param = PDO::PARAM_INT;

            if (preg_match('/[a-z0-9A-Z_-]+|éàèëïùöôîüµ$£!?\.\+,;:/', $value) && !is_numeric($value)) {
                /**
                 * SECURITY OF DATA
                 * - Injection SQL
                 * - XSS
                 */
                $param = PDO::PARAM_STR;
            } else {
                /**
                 * We force the value in whole or in reel.
                 */
                if (is_int($value)) {
                    $value = (int) $value;
                } elseif (is_float($value)) {
                    $value = (float) $value;
                } else {
                    $value = (double) $value;
                }
            }

            if (is_string($key)) {
                $pdo_statement->bindValue(':' . $key, $value, $param);
            } else {
                $pdo_statement->bindValue($key + 1, $value, $param);
            }
        }

        return $pdo_statement;
    }
9021
public function bindValues(
        /*# string */ $sql,
        array &$bindings,
        array $settings
    )/*# : string */ {
        // make sure escape function ok
        $this->setEscapeCallable($settings['escapeFunction']);

        // replace each placeholder with corresponding ?/:name/value
        return preg_replace_callback(
            '/\b__PHQUERY_[^_]++__\b/',
            function ($m) use (&$bindings, $settings) {
                return $this->replacePlaceholders($m[0], $bindings, $settings);
            },
            $sql
        );
    }
1362423
public static function executeStatement(
        PDOStatement $statement,
        array $params = null
    ) {
        //Add the statement to the list of those run
        static::addStatement($statement);

        //Add bindings to the statement
        if (is_array($params)) {
            $statement->getBindings()
                ->hydrateFromArray($params);
        }

        $result = static::getOrCreateResultAt(static::numQueries());

        //Add the result to the statement
        $statement->setResult($result);

        //If a transaction is open, add the statement to it
        if (static::inTransaction()) {
            static::currentTransaction()->addStatement($statement);
        }

        //Increment number of queries run
        static::incrementNumQueries();

        if (static::shouldLogBacktrace()) {
            $statement->setBacktrace(
                static::makeBacktraceCollection(
                    debug_backtrace(
                        DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS,
                        static::resolveBacktraceLimit()
                    )
                )
            );
        }
    }
676801
function prepare($sql, $driver_options = [])
    {
//        if (isset($this->statements[$sql])){
//            return $this->statements[$sql];
//        }
        if ($this->trace_sql || $this->trace_count){
            $stmt = parent::prepare($this->addPrefixes($sql), $driver_options);
            if ($stmt instanceof PDOStatement){
                return /*$this->statements[$sql] = */new DBStatementDebug($stmt, $this->trace_sql, $this->trace_count, $this->slow_query);
            }else{
                throw new Error('PDO does not return PDOStatement');
            }
        }
        return /*$this->statements[$sql] = */parent::prepare($this->addPrefixes($sql), $driver_options);
    }
633700
public function insertBatch(string $table, $data=[]): ?PDOStatement
	{
		// Get the generated values and sql string
		[$sql, $data] = $this->driver->insertBatch($table, $data);

		return $sql !== NULL
			? $this->_run('', $table, $sql, $data)
			: NULL;
	}
353511
protected function bindValue(array $bind = []) {
        foreach ($bind as $key => $val) {
            // 占位符
            $param = is_numeric($key) ? $key + 1 : ':' . $key;
            if (is_array($val)) {
                if (PDO::PARAM_INT == $val[ 1 ] && '' === $val[ 0 ]) {
                    $val[ 0 ] = 0;
                }
                $this->PDOStatement->bindValue($param, $val[ 0 ], $val[ 1 ]);
            } else {
                $this->PDOStatement->bindValue($param, $val);
            }
        }
    }