0

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

我没有错误显示,没有语法亵渎,它只是不打印任何结果。但是,我知道这些值是通过表单传递给这个处理 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 代码恢复的

4

1 回答 1

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

应该

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

或者

SELECT company FROM accesoweb WHERE AES_DECRYPT(username, 'salt') = ?
于 2012-05-27T17:40:30.360 回答