【发布时间】:2015-06-25 09:59:21
【问题描述】:
我想知道将 $variable 传递给查询的安全或正确方法。我是 PHP 新手,这就是为什么我要问这样的初学者问题。下面是例子一和二,由于符号的原因,哪一个是正确和安全的?
示例一:
//here is the line I am asking about. The $identification
$query = "SELECT * FROM `members` WHERE `username` = '$identification' LIMIT 1";
示例二:
//here is the line I am asking about. The $identification
$query = "SELECT * FROM `members` WHERE `username` = '" . $identification . "' LIMIT 1";
我不需要有关 PHP 4 或 5 或 PDO 的答案。我只需要知道什么是正确的:
这个
'" . $identification . "'
或者这个
'$identification'
【问题讨论】:
-
无法在我的共享主机提供商上运行 php 5
-
我不敢相信,你的 php 版本是多少?您的托管服务提供商是谁?
-
“无法在我的共享主机提供商上运行 php 5” - 您的问题中有
mysqli_代码。你猜怎么了;mysqli_在 PHP 5 上运行。php.net/manual/en/class.mysqli.php -
你好,弗雷德。真的吗?我的托管服务提供商说他们运行 4.5 或 4 点的东西。我试图运行一个脚本,但它没有工作
标签: php mysql arrays variables mysqli