小飞鱼通达二开 处理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;

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

小飞鱼通达二开 CSDN认证博客专家 软件开发平台 通达OA二次开发 工作流系统集成
知识范围主要涉及SCJP 、MCP、CCNA、通达OA二次开发、OA系统及微信系统的系统集成与整合。对通达OA二次开发进行深入研究与探索,主要研究信息化软件系统的整合与开发工作。

如何修复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>

致命错误:未捕获PDOException:SQLSTATE [HY000]:常规错误:获取模式需要classname参数in

06-08
<div class="post-text" itemprop="text"> <p>When I use <code>FETCH_CLASS</code> the following error come but when I use <code>FETCH_OBJ</code> the page loads correctly. Please help me to solve this.</p> <p>The error is:</p> <blockquote> <p>Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: fetch mode requires the classname argument in C:\xampp\htdocs\Work\AppDarbNajah\App\Database.php:51 Stack trace: #0 C:\xampp\htdocs\Work\AppDarbNajah\App\Database.php(51): PDOStatement->setFetchMode(8) #1 C:\xampp\htdocs\Work\AppDarbNajah\App\Model\Model.php(62): App\Database->query('SELECT ...', false, 'App\Entity\Arti...') #2 C:\xampp\htdocs\Work\AppDarbNajah\App\Model\ArticleModel.php(9): App\Model\Model->query('SELECT ...') #3 C:\xampp\htdocs\Work\AppDarbNajah\App\Controller\ArticleController.php(16): App\Model\ArticleModel->load() #4 C:\xampp\htdocs\Work\AppDarbNajah\Public\index.php(33): App\Controller\ArticleController->index() #5 {main} thrown in C:\xampp\htdocs\Work\AppDarbNajah\App\Database.php on line 51</p> </blockquote> <p>1- code of Database:</p> <pre><code><?php namespace App; use \PDO; /* Connect to a MySQL database using driver invocation */ class Database{ private $db_host; private $db_name; private $db_user; private $db_pass; private $pdo; public function __construct($db_name, $db_host = 'localhost', $db_user = 'root', $db_pass = ''){ $this->db_name = $db_name; $this->db_host = $db_host; $this->db_user = $db_user; $this->db_pass = $db_pass; } private function getPDO() { if($this->pdo === null){ $pdo = new PDO( 'mysql:host='.$this->db_host.';dbname='.$this->db_name, $this->db_user, $this->db_pass ); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->query(' SET NAMES utf8; SET CHARACTER SET UTF8 '); $this->pdo = $pdo; } return $this->pdo; } public function query($statement, $one = false, $class = null){ $rs = $this->getPDO()->query($statement); if( strpos(strtolower($statement), 'insert') === 0 || strpos(strtolower($statement), 'delete') === 0 || strpos(strtolower($statement), 'update') === 0 ){ return $rs; } if($class === null){ $rs->setFetchMode(PDO::FETCH_OBJ); } else { $rs->setFetchMode(PDO::FETCH_CLASS); } if($one){ $data = $rs->fetch(); } else { $data = $rs->fetchAll(); } return $data; } public function prepare($statement, $attributes, $one = false, $class = null){ $rs = $this->getPDO()->prepare($statement); $rst = $rs->execute($attributes); if( strpos(strtolower($statement), 'insert') === 0 || strpos(strtolower($statement), 'delete') === 0 || strpos(strtolower($statement), 'update') === 0 ){ return $rst; } if($class === null){ $rs->setFetchMode(PDO::FETCH_OBJ); } else { $rs->setFetchMode(PDO::FETCH_CLASS); } if($one){ $data = $rs->fetch(); } else { $data = $rs->fetchAll(); } return $data; } } </code></pre> <p>2- code of model:</p> <pre><code><?php namespace App\Model; use App\Database; class Model{ protected $db; protected $table; public function __construct(Database $db){ $this->db = $db; //var_dump(get_class($this)); } public function create($fields){ var_dump($fields); $sql_pairs = []; $attributes = []; foreach ($fields as $k =>$v){ $sql_pairs[] = "$k = ?";/*راجع درس PDO*/ $attributes[] = $v; } $sql_parts = implode(', ', $sql_pairs); $this->query("INSERT INTO {$this->table} SET $sql_parts", $attributes); } public function update($id, $fields){ } public function delete($id){ } public function search($id, $fields = null){ } public function query($statement, $attributes= null, $one = false){ var_dump(get_class($this)); var_dump(str_replace('Model', 'Entity', get_class($this))); //die(); if($attributes){ return $this->db->prepare( $statement, $attributes, $one, str_replace('Model', 'Entity', get_class($this)) ); } else{ return $this->db->query( $statement, $one, str_replace('Model', 'Entity', get_class($this)) ); } } } </code></pre> </div>

关于ODBC中SQLDriverConnect 和 SQLDriverConnectW连接问题

06-30
Hi,Guys 在采用unixODBC连接Mysql数据库,遇到以下问题: 使用SQLDriverConnect进行连接,正常 使用SQLDriverConnectW进行连接,出现下面的错误,说数据源找不到. ``` [unixODBC][Driver Manager]Data source name not found, and no default driver specified ``` --- 采用的都是同样的配置 环境: mysql-connector-odbc-5.3.4-linux-glibc2.5-x86-32bit unixODBC 2.3.2 --- 配置信息 **odbcinst.ini** ``` bash [MySQL] Driver = /usr/local/lib/libmyodbc5w.so ``` **odbc.ini** ``` bash [log4cxx] Driver = MySQL Server = localhost Port = 3306 Database= log User = root Password= 123456 Socket = /var/run/mysqld/mysqld.sock ``` **C代码 SQLDriverConnectW** ``` python int main() { SQLHENV env; SQLHDBC dbc; SQLRETURN ret; /* ODBC API return status */ SQLWCHAR outstr[1024]; SQLSMALLINT outstrlen; SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env); SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc); ret = SQLDriverConnectW(dbc, NULL, (SQLWCHAR *)"DSN=log4cxx;", SQL_NTS, outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT); if(ret < 0) { printf("asdfasdfasdfsadfsadf\n"); } if (SQL_SUCCEEDED(ret)) { printf("Connected\n"); if (ret == SQL_SUCCESS_WITH_INFO) { printf("Driver reported the following diagnostics\n"); extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC); } SQLDisconnect(dbc);/* disconnect from driver */ } else { fprintf(stderr, "Failed to connect\n"); extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC); } /* free up allocated handles */ SQLFreeHandle(SQL_HANDLE_DBC, dbc); SQLFreeHandle(SQL_HANDLE_ENV, env); return 0; } ``` **C代码 SQLDriverConnect** ``` c int main() { SQLHENV env; SQLHDBC dbc; SQLRETURN ret; /* ODBC API return status */ SQLCHAR outstr[1024]; SQLSMALLINT outstrlen; SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env); SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc); ret = SQLDriverConnect(dbc, NULL, (SQLCHAR *)"DSN=log4cxx;", SQL_NTS, outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT); if(ret < 0) { printf("asdfasdfasdfsadfsadf\n"); } if (SQL_SUCCEEDED(ret)) { printf("Connected\n"); if (ret == SQL_SUCCESS_WITH_INFO) { printf("Driver reported the following diagnostics\n"); extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC); } SQLDisconnect(dbc);/* disconnect from driver */ } else { fprintf(stderr, "Failed to connect\n"); extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC); } /* free up allocated handles */ SQLFreeHandle(SQL_HANDLE_DBC, dbc); SQLFreeHandle(SQL_HANDLE_ENV, env); return 0; } ```
©️2020 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值