dongwei6457 2012-05-27 16:43
浏览 37
已采纳

php准备好的声明

It does not print the result. Dont know why. Everything is neatly commented

I get no error displays, no syntax blasphemes, it just does not print any result. However, I do know that the values are passed by the form to this processing php page, so the error is not in there. In the DB I have encrypted all fields except 'company'- Thus, I want to see if this will work by trying to fetch the results back.

// 1. Creating a new server connection

$db = new mysqli('localhost', 'root', '', 'developers');
if ($db->connect_errno) {
    printf("Connect failed: %s
", $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.
", $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(); 

}

The inserting code that I just included in the MySQL was:

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


);

So, that row above(actually, the "company" is what I am trying to recover through the PHP code

  • 写回答

1条回答 默认 最新

  • dsp15140275697 2012-05-27 17:40
    关注
    SELECT company FROM accesoweb WHERE username = AES_DECRYPT(?, 'salt')
    

    Should be

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

    OR

    SELECT company FROM accesoweb WHERE AES_DECRYPT(username, 'salt') = ?
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题