小飞鱼通达二开 处理PDO连接数据库时的Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]报错

之前在小飞鱼本机上开发的程序,使用了PDO方式连接mysql数据库,今天在部署到服务器上时居然不显示数据,查找日志文件出现下面的信息:

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared

开始以为是这个机器上的PDO没有配置开放,试着调了下php.ini文件中的pdo选项,重启服务后问题没有得到解决。

期间试了一下其他页面的程序,发现有的页面上时可以直接显示数据的,唯独这个页面有问题,而这个页面里用到了分页、视图这些,经过进一步查找资料,发现是视图里使用了左连接,查询mysql的cache参数:

SHOW VARIABLES LIKE '%table_open_cache%';
SHOW VARIABLES LIKE '%table_definition_cache%';

发现有一个cache设置的比较小,调整一下:

SET GLOBAL table_open_cache=16384;
SET GLOBAL table_definition_cache=16384;

执行查询后,数据可以正常显示了。

展开阅读全文

如何修复PHP中的“Uncaught PDOException:SQLSTATE [22007]”致命错误

04-28
<div class="post-text" itemprop="text"> <p>I have problem with add new data to database using PDO. I have a form where there are several fields. If I leave an empty field then an error pops up. The problem occurred when mysql was updated on the server. On another server and locally the problem does not appear. Setting the server in all forms to default values of 0 in the fields will be very difficult.</p> <p>Database version: 10.3.13-MariaDB-100.cba.1-log - Debian testing</p> <p>Please, check if you do not complete all the fields and generate an error.</p> <p>Is it ok when I leave empty input then error generated?</p> <p>PHP Code:</p> <pre><code>$config = require_once 'config.php'; try { $db = new PDO( "mysql:host={$config['host']};dbname={$config['database']};charset=utf8", $config['user'],$config['password'], [PDO::ATTR_EMULATE_PREPARES=>false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); } catch(PDOException $error) { echo $error->getMessage(); exit('Database error!'); } if (isset($_POST['dodaj'])) { $pole1 = $_POST['pole1']; $pole2 = $_POST['pole2']; $pole3 = $_POST['pole3']; $pole4 = $_POST['pole4']; $query = $db->prepare("INSERT into pola VALUES (:pole1, :pole2, :pole3, :pole4)"); $query->bindValue(':pole1', $pole1, PDO::PARAM_INT); $query->bindValue(':pole2', $pole2, PDO::PARAM_INT); $query->bindValue(':pole3', $pole3, PDO::PARAM_INT); $query->bindValue(':pole4', $pole4, PDO::PARAM_INT); $query->execute(); } </code></pre> <p>HTML code:</p> <pre><code><form method="post" action="#"> <input type="text" id="pole1" name="pole1"> <input type="text" id="pole2" name="pole2"> <input type="text" id="pole3" name="pole3"> <input type="text" id="pole4" name="pole4"> <input type="submit" name="dodaj" value="dodaj"> </form> </code></pre> <p>Database:</p> <p>pole1 | pole2 | pole3 | pole4</p> <blockquote> <p>Fatal error: Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column <code>********</code>.<code>pola</code>.<code>pole3</code> at row 1 in ************************new 1.php:18 Stack trace: #0 ********************new 1.php(18): PDOStatement->execute() #1 {main} thrown in ******************************new 1.php on line 18</p> </blockquote> </div>
©️2020 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值