php - "x = ?"在 SQL 查询条件下意味着什么?

标签 php sql

<分区>

我需要帮助来弄清楚这句话的意思:

SELECT id, username, password FROM users WHERE email = ?LIMIT 1

我知道 LIMIT 1 是什么意思,但是 '= ?' 是什么意思?

最佳答案

这是一个prepared statement .

A prepared statement or a parameterized statement is used to execute the same statement repeatedly with high efficiency.

The prepared statement execution consists of two stages: prepare and execute. At the prepare stage a statement template is sent to the database server. The server performs a syntax check and initializes server internal resources for later use.

Prepare is followed by execute. During execute the client binds parameter values and sends them to the server. The server creates a statement from the statement template and the bound values to execute it using the previously created internal resources.

A prepared statement can be executed repeatedly. Upon every execution the current value of the bound variable is evaluated and sent to the server. The statement is not parsed again. The statement template is not transferred to the server again.

Every prepared statement occupies server resources. Statements should be closed explicitly immediately after use. If not done explicitly, the statement will be closed when the statement handle is freed by PHP.

Using a prepared statement is not always the most efficient way of executing a statement. A prepared statement executed only once causes more client-server round-trips than a non-prepared statement.

This example performs an INSERT query by substituting a name and a value for the positional ? placeholders.

<?php
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)");
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $value);

// insert one row
$name = 'one';
$value = 1;
$stmt->execute();

我建议阅读整个教程。您还应该查看 PDO .

关于php - "x = ?"在 SQL 查询条件下意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23281711/

相关文章:

php - Laravel Microsoft Sql Server 连接错误

sql - 使用查询在 HP Vertica 中创建表的 SQL

sql - 在SQL Server中查找第100条、200条等记录

php - 用于 Postgresql 查询的 PHP 中列名的绑定(bind)变量

mysql - SQL顺序消除

php mysql - 选择以下划线开头的表

php - 如何在 php 中为循环中的 div 提供 3 种不同的颜色

php - ajax octobercms传递id值

php - 在 PHP 中是否有任何等效函数返回位置 `X` 处的字符?

mysql - SQL:获取每个主题的最后 3 个帖子