gpt4 book ai didi

php - 用php加密postgres中的数据

转载 作者:行者123 更新时间:2023-11-29 13:06:06 25 4
gpt4 key购买 nike

我需要在我的 postgres 数据库中存储一个加密的数字。我想使用带有 3DES 功能的 mcrypt,加密和解密工作正常,但我不能将它存储在数据库中。我的数据库字段是 char(50)

$key = "this is a secret key";
$input = "123456789";

$test = mcrypt_ecb(MCRYPT_3DES, $key, $input, MCRYPT_ENCRYPT);
$db = pg_connect("host=localhost dbname=testdb user=haxo");
$sql = "insert into test (pin) values('".$test."')";
$result = pg_query($sql);
if (!$result) {
$errormessage = pg_last_error();
echo "Error with query: " . $errormessage;
exit();
}
pg_close();

我得到的错误是:错误:“'Şlä”处或附近未终止的引号字符串

最佳答案

使字段类型为 BYTEA(用于存储二进制字符串),然后使用 PDO prepare、bindValue、execute 之类的东西来插入值。

还有,你知道sql injection吗? ?您使用的编码模式很容易引发麻烦。

关于php - 用php加密postgres中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11519294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com