Php YII CActiveRecord->;查找()
我现在还在博客教程上学习YII,对一些代码很好奇 在这个链接上Php YII CActiveRecord->;查找(),php,yii,yii-cactiverecord,Php,Yii,Yii Cactiverecord,我现在还在博客教程上学习YII,对一些代码很好奇 在这个链接上 有这样的代码 <?php class UserIdentity extends CUserIdentity { private $_id; public function authenticate() { $username=strtolower($this->username); $user=User::model()->find('LOWER(username)=?',array($user
有这样的代码
<?php
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$username=strtolower($this->username);
$user=User::model()->find('LOWER(username)=?',array($username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;
$this->username=$user->username;
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}
public function getId()
{
return $this->_id;
}
}
在代码的最后一行
$user=user::model()->find('LOWER(username)=?',array($username))代码>为什么使用LOWER(username)=?
不LOWER(username)=
。为什么需要?
,这是我还不知道的查询条件吗
?>
实际上并不需要,根据:
文件末尾的PHP块的结束标记是可选的,在某些情况下,当使用include()或require()时,省略它会很有帮助,因此不需要的空格不会出现在文件末尾,您以后仍然可以向响应中添加头。如果您使用输出缓冲,并且不希望在包含的文件生成的部分末尾添加不需要的空白,那么它也很方便
?
与从中看到的SQL语法相关。该报告还说:
问号表示稍后将替换的参数。使用参数化查询比将参数直接嵌入查询更安全