php准备好的声明

时间:2012-05-27 16:43:40

标签: php

不打印结果。不知道为什么。一切都被整齐地评论

我没有显示错误,没有语法亵渎,它只是不打印任何结果。但是,我知道这些值是由表单传递给这个处理php页面的,所以错误不在那里。在数据库中我加密了除“公司”以外的所有字段 - 因此,我想通过尝试获取结果来查看这是否有效。

// 1. Creating a new server connection

$db = new mysqli('localhost', 'root', '', 'developers');
if ($db->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
// 2, Creating statement object
$stmt = $db->stmt_init();

// 3, Creating a prepared statement
if($stmt->prepare("SELECT company FROM accesoweb WHERE username = AES_DECRYPT(?, 'salt')")) {

//4. Binding the variable to replace the ?
    $stmt->bind_param('s', $username);

    printf("Error: %d.\n", $stmt->errno);


// 5. Executing query
    $stmt->execute();


// 6. Binding the result columns to variables
    $stmt->bind_result($company); 


// 7. Fetching the result of the query
    while($stmt->fetch()) {
        echo $company; 
    }

// 8. Closing the statement object
   $stmt->close();

// 9. Closing the connection

 $mysqli->close(); 

}

我刚刚包含在MySQL中的插入代码是:

INSERT INTO accesoweb (company, username,email,password)
VALUES
 ('hola',
AES_ENCRYPT('maria','salt'),
AES_ENCRYPT('sumail','salt'),
AES_ENCRYPT('password',' salt')


);

所以,上面那一行(实际上,“公司”是我试图通过PHP代码恢复的

1 个答案:

答案 0 :(得分:2)

SELECT company FROM accesoweb WHERE username = AES_DECRYPT(?, 'salt')

应该是

SELECT company FROM accesoweb WHERE username = AES_ENCRYPT(?, 'salt')

OR

SELECT company FROM accesoweb WHERE AES_DECRYPT(username, 'salt') = ?