gpt4 book ai didi

php - mysqli 插入查询的结果不稳定

转载 作者:行者123 更新时间:2023-11-29 00:01:45 24 4
gpt4 key购买 nike

我正在使用完全相同的参数运行相同的 mysqli 插入查询。大约有 1/3 的时间是成功的,我不知道哪里出了问题。

<?php
//...
$decrypted_session_key = 'unavailable'; // initialize
$res = openssl_get_privatekey($priv_key, $passphrase);
$result = openssl_private_decrypt($encrypted_session_key, $decrypted_session_key, $res, OPENSSL_PKCS1_OAEP_PADDING);

if ($decrypted_session_key == 'unavailable') {
mysqli_close($link);
echo json_encode(array('result' => 'failed', 'message' => 'failed to decrypt the session key'));
die();
}

if (!$decrypted_session_key) {
echo json_encode(array('result'=>'failed', 'message'=>'decrypted session key has failed'));
die();
}

$updated_at = date("Y-m-d H:i:s");

// save this record to the database
$result = mysqli_query($link, "INSERT INTO Session_Keys (session_id, session_key, iv, updated_at)
VALUES ($session_id, '$decrypted_session_key', '$iv', '$updated_at')");

if (!$result) {
$param_check = $session_id . " " . base64_encode($iv) . " " . base64_encode($decrypted_session_key) . " " . $updated_at;
echo json_encode(array('result'=>'failed', 'message'=>$param_check));
die();
}

// ...
}

每当失败时,我都会返回最后一个 echo 语句。我怀疑 php 解密例程失败了,但事实并非如此。所有的参数都是完美的,包括解密值。是我的插入语句错误的问题吗?我尝试了引用字段的各种组合,但没有任何一致的结果。

表结构是这样的:

'session_id' int(11)
'session_key' tinyblob
'iv' 小 Blob
'updated_at' 日期时间

enter image description here我不明白为什么我的结果如此不一致。如果失败了,为什么不每次都失败呢?如果有效,为什么不是每次都有效?很困惑。任何帮助表示赞赏。谢谢!

最佳答案

在评论中向 OP 建议使用 or die(mysqli_error($link))mysqli_query() 让他们找到查询失败的原因.

他们的评论:

"I finally got at the error message here it is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<´§y?'T]î‘Á gô, EÈöJÀÊ?Xû¶T¢ÑÖ?, 2015-04-05 19:26:00)' at line 2 Must be something to do with the bytes that I am trying to store."

"Now I understand the problem. Your suggestion about looking at mysqli_error is what led me to the solution (after lots of difficulty on my end to gain access to it!). The real error (after I correctly quoted my fields) is Duplicate entry '2147483647' for key 'PRIMARY'. My ios app is randomly assigning an unsigned integer value (0 - 4294967294) but an int(11) field maxex out at 2147483647. So, half of my values were received as duplicates, thereby causing an error. Problem solved. Thanks for your help!"


来自:

https://stackoverflow.com/a/17783287/

2147483647是mysql最大的int值。只需将类型从 int 更改为 bigint。

  • 解释了重复的错误。

关于php - mysqli 插入查询的结果不稳定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29460669/

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