【问题标题】:cakePHP prepared statement not working (fetch all not working)cakePHP 准备好的语句不工作(获取所有不工作)
【发布时间】:2016-06-27 23:18:28
【问题描述】:

我正在使用 cakePHP,但不知道如何准备 sql 语句。我已经尝试了很多东西,但似乎没有任何效果。我正在使用 sql server 2014。

在食谱中,我找到了准备好的语句的确切代码:

    $db = $this->getDataSource();
    $db->fetchAll(
        'SELECT * from users where username = :username AND password = :password',
        array('username' => 'jhon','password' => '12345')
    );

但是,当我尝试使用此代码时(只是为了看看我是否可以使用它),这是我的结果:

警告 (512):SQL 错误:第 1 行:':' 附近的语法不正确。 [APP/Model/Datasource/Mssql.php,第 749 行]

和我的调试:

查询:SELECT * from users where username = :username AND password = :password

有谁知道为什么这不起作用?任何帮助都会很棒,谢谢!

【问题讨论】:

    标签: php sql-server cakephp prepared-statement cakephp-2.0


    【解决方案1】:

    试试这个:

    $db = $this->getDataSource();
    $username = 'jhon';
    $password = '12345';
    $db->fetchAll("SELECT * from users where username = $username AND password = $password");
    

    【讨论】:

    • 这不是问题的解决方案。所有这一切都是将变量的值叠加到字符串中。 sql注入时机成熟了。
    猜你喜欢
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多