<tfoot id='o1A1r'></tfoot>

      <bdo id='o1A1r'></bdo><ul id='o1A1r'></ul>
        <legend id='o1A1r'><style id='o1A1r'><dir id='o1A1r'><q id='o1A1r'></q></dir></style></legend>

        <small id='o1A1r'></small><noframes id='o1A1r'>

        <i id='o1A1r'><tr id='o1A1r'><dt id='o1A1r'><q id='o1A1r'><span id='o1A1r'><b id='o1A1r'><form id='o1A1r'><ins id='o1A1r'></ins><ul id='o1A1r'></ul><sub id='o1A1r'></sub></form><legend id='o1A1r'></legend><bdo id='o1A1r'><pre id='o1A1r'><center id='o1A1r'></center></pre></bdo></b><th id='o1A1r'></th></span></q></dt></tr></i><div id='o1A1r'><tfoot id='o1A1r'></tfoot><dl id='o1A1r'><fieldset id='o1A1r'></fieldset></dl></div>

        Laravel:一般错误:1615 Prepared statement需要重新准备

        Laravel: General error: 1615 Prepared statement needs to be re-prepared(Laravel:一般错误:1615 Prepared statement需要重新准备)

          • <bdo id='6XZQA'></bdo><ul id='6XZQA'></ul>
              <tbody id='6XZQA'></tbody>
            • <i id='6XZQA'><tr id='6XZQA'><dt id='6XZQA'><q id='6XZQA'><span id='6XZQA'><b id='6XZQA'><form id='6XZQA'><ins id='6XZQA'></ins><ul id='6XZQA'></ul><sub id='6XZQA'></sub></form><legend id='6XZQA'></legend><bdo id='6XZQA'><pre id='6XZQA'><center id='6XZQA'></center></pre></bdo></b><th id='6XZQA'></th></span></q></dt></tr></i><div id='6XZQA'><tfoot id='6XZQA'></tfoot><dl id='6XZQA'><fieldset id='6XZQA'></fieldset></dl></div>

                <legend id='6XZQA'><style id='6XZQA'><dir id='6XZQA'><q id='6XZQA'></q></dir></style></legend>

                  <tfoot id='6XZQA'></tfoot>

                  <small id='6XZQA'></small><noframes id='6XZQA'>

                1. 本文介绍了Laravel:一般错误:1615 Prepared statement需要重新准备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在宅基地虚拟机 (vagrant) 中使用最新版本的 laravel (5.1).

                  I'm using last version of laravel (5.1) in a homestead virtual machine (vagrant).

                  我将我的项目连接到本地 mariaDB 服务器,其中我有一些表和 2 个 db-view.

                  I connect my project to a local mariaDB server, in which I have some table and 2 db-view.

                  由于我仅在 db-view 表上进行了一些选择,因此我随机收到此错误:

                  Since I made some select only on the db-view tables, I receive back randomly this error:

                  一般错误:1615 Prepared statement需要重新准备

                  General error: 1615 Prepared statement needs to be re-prepared

                  从今天开始,当只在数据库视图上进行选择时,我总是会收到此错误.如果我打开我的 phpMyAdmin 并进行相同的选择,它会返回正确的结果.

                  From today, I always get this error when made select only on the db views. If I open my phpMyAdmin and make the same select it return the correct result.

                  我试图打开 php artisan tinker 并选择 db-view 的一条记录,但它返回相同的错误:

                  I tried to open php artisan tinker and select one record of the db-view but it return the same error:

                  // Select one user from user table
                  >>> $user = new AppUser
                  => <AppUser #000000006dc32a890000000129f667d2> {}
                  >>> $user = AppUser::find(1);
                  => <AppUser #000000006dc32a9e0000000129f667d2> {
                         id: 1,
                         name: "Luca",
                         email: "luca@email.it",
                         customerId: 1,
                         created_at: "2015-08-06 04:17:57",
                         updated_at: "2015-08-11 12:39:01"
                     }
                  >>> 
                  // Select one source from Source db-view
                  >>> $source = new AppSource
                  => <AppSource #000000006dc32a820000000129f667d2> {}
                  >>> $source = AppSource::find(1);
                  IlluminateDatabaseQueryException with message 'SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: select * from `sources` where `sources`.`id` = 1 limit 1)'
                  

                  我该如何解决这个问题?我读到了 mysqldump 的一个问题(但在我的情况下不是)并增加了 table_definition_cache 的值,但不确定它是否会起作用,我无法修改它们.

                  How can I fix that? I read about a problem with mysqldump (but not in my case) and to increase value of table_definition_cache but it is not sure that it will work and I can't modify them.

                  这是一种 laravel 的 bug 吗?

                  Is this a kind of laravel bug?

                  我怎么知道?

                  按照要求,我添加了我的模型源代码.源码.php:

                  As asked, I add my model source code. Source.php:

                  <?php
                  
                  namespace App;
                  
                  use IlluminateDatabaseEloquentModel;
                  
                  class Source extends Model
                  {
                      protected $table = 'sources';
                  
                  
                      /*
                      |--------------------------------------------------------------------------
                      | FOREIGN KEYS
                      |--------------------------------------------------------------------------
                      */
                  
                      /**
                       * 
                       * @return [type] [description]
                       */
                      public function customersList(){
                          return $this->hasMany("AppCustomerSource", "sourceId", "id");
                      }
                  
                  
                      /**
                       * 
                       * @return [type] [description]
                       */
                      public function issues(){
                          return $this->hasMany("AppIssue", "sourceId", "id");
                      }
                  }
                  

                  <小时>

                  编辑 2:


                  Edit 2:

                  如果我在项目中使用 mysqli 执行相同的查询,它会起作用:

                  If I execute the same query in the project with mysqli it works:

                  $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'));
                  if($db->connect_errno > 0){
                      dd('Unable to connect to database [' . $db->connect_error . ']');
                  }
                  $sql = "SELECT * FROM `sources` WHERE `id` = 4";
                  if(!$result = $db->query($sql)){
                      dd('There was an error running the query [' . $db->error . ']');
                  }
                  
                  dd($result->fetch_assoc());
                  

                  <小时>

                  编辑 3:2个月后,我还在.同样的错误,没有找到解决方案.我决定在 aritsan tinker 中尝试一个小解决方案,但没有好消息.我报告了我的尝试:


                  EDIT 3: Afeter 2 month, I'm still there. Same error and no solution found. I decide to try a little solution in aritsan tinker but no good news. I report what I've tried:

                  首先尝试获取一个表模型:

                  First try to fetch a table model:

                  >>> $user = AppUser::find(1);
                  => AppUser {#697
                       id: 1,
                       name: "Luca",
                       email: "luca.d@company.it",
                       customerId: 1,
                       created_at: "2015-08-06 04:17:57",
                       updated_at: "2015-10-27 11:28:14",
                     }
                  

                  现在尝试获取视图表模型:

                  Now try to fetch a view table model:

                  >>> $ir = AppContentRepository::find(15);
                  IlluminateDatabaseQueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbname.content_repositories' doesn't exist (SQL: select * from `content_repositories` where `content_repositories`.`id` = 1 limit 1)'
                  

                  当 contentRepository 在模型 ContentRepository.php 中没有正确的表名设置时:

                  When contentRepository doesn't have correct table name setup inside the model ContentRepository.php:

                  >>> $pdo = DB::connection()->getPdo();
                  => PDO {#690
                       inTransaction: false,
                       errorInfo: [
                         "00000",
                         1146,
                         "Table 'dbname.content_repositories' doesn't exist",
                       ],
                       attributes: [
                         "CASE" => NATURAL,
                         "ERRMODE" => EXCEPTION,
                         "AUTOCOMMIT" => 1,
                         "PERSISTENT" => false,
                         "DRIVER_NAME" => "mysql",
                         "SERVER_INFO" => "Uptime: 2513397  Threads: 12  Questions: 85115742  Slow queries: 6893568  Opens: 1596  Flush tables: 1  Open tables: 936  Queries per second avg: 33.864",
                         "ORACLE_NULLS" => NATURAL,
                         "CLIENT_VERSION" => "mysqlnd 5.0.11-dev - 20120503 - $Id: id_here $",
                         "SERVER_VERSION" => "5.5.5-10.0.17-MariaDB-1~wheezy-wsrep-log",
                         "STATEMENT_CLASS" => [
                           "PDOStatement",
                         ],
                         "EMULATE_PREPARES" => 0,
                         "CONNECTION_STATUS" => "localiphere via TCP/IP",
                         "DEFAULT_FETCH_MODE" => BOTH,
                       ],
                     }
                  >>> 
                  

                  在模型 ContentRepository.php 中更改表值:

                  CHANGE TABLE VALUE INSIDE model ContentRepository.php:

                  >>> $ir = AppContentRepository::find(15);
                  IlluminateDatabaseQueryException with message 'SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: select * from `contentRepository` where `contentRepository`.`id` = 15 limit 1)'
                  

                  正确时,注意缺少的errorInfo":

                  >>> $pdo = DB::connection()->getPdo();
                  => PDO {#690
                       inTransaction: false,
                       attributes: [
                         "CASE" => NATURAL,
                         "ERRMODE" => EXCEPTION,
                         "AUTOCOMMIT" => 1,
                         "PERSISTENT" => false,
                         "DRIVER_NAME" => "mysql",
                         "SERVER_INFO" => "Uptime: 2589441  Threads: 13  Questions: 89348013  Slow queries: 7258017  Opens: 1604  Flush tables: 1  Open tables: 943  Queries per second avg: 34.504",
                         "ORACLE_NULLS" => NATURAL,
                         "CLIENT_VERSION" => "mysqlnd 5.0.11-dev - 20120503 - $Id: id_here $",
                         "SERVER_VERSION" => "5.5.5-10.0.17-MariaDB-1~wheezy-wsrep-log",
                         "STATEMENT_CLASS" => [
                           "PDOStatement",
                         ],
                         "EMULATE_PREPARES" => 0,
                         "CONNECTION_STATUS" => "localIPhere via TCP/IP",
                         "DEFAULT_FETCH_MODE" => BOTH,
                       ],
                     }
                  

                  显示 db 的表:

                  >>> $tables = DB::select('SHOW TABLES');
                  => [
                       {#702
                         +"Tables_in_dbname": "table_name_there",
                       },
                       {#683
                         +"Tables_in_dbname": "table_name_there",
                       },
                       {#699
                         +"Tables_in_dbname": "table_name_there",
                       },
                       {#701
                         +"Tables_in_dbname": "table_name_there-20150917-1159",
                       },
                       {#704
                         +"Tables_in_dbname": "contentRepository", */ VIEW TABLE IS THERE!!!! /*
                       },
                       {#707
                         +"Tables_in_dbname": "table_name_there",
                       },
                       {#684
                         +"Tables_in_dbname": "table_name_there",
                       },
                     ]
                  

                  尝试正常选择:

                  >>> $results = DB::select('select * from dbname.contentRepository limit 1');
                  IlluminateDatabaseQueryException with message 'SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: select * from dbname.contentRepository limit 1)'
                  

                  尝试未准备的查询:

                  >>> DB::unprepared('select * from dbname.contentRepository limit 1')
                  => false
                  

                  尝试第二次未准备的查询:

                  Try second time unprepared query:

                  >>> DB::unprepared('select * from dbname.contentRepository limit 1')
                  IlluminateDatabaseQueryException with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. (SQL: select * from dbname.contentRepository limit 1)'
                  

                  试试 PDOStatement::fetchAll():

                  Try PDOStatement::fetchAll():

                  >>> DB::fetchAll('select * from dbname.contentRepository limit 1'); 
                  PHP warning:  call_user_func_array() expects parameter 1 to be a valid callback, class 'IlluminateDatabaseMySqlConnection' does not have a method 'fetchAll' in /Users/luca/company/Laravel/dbname/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php on line 296
                  

                  尝试第二个 PDOStatement::fetchAll():

                  Try second PDOStatement::fetchAll():

                  >>> $pdo::fetchAll('select * from dbname.contentRepository limit 1');
                    [SymfonyComponentDebugExceptionFatalErrorException]  
                    Call to undefined method PDO::fetchAll()           
                  

                  Try 语句...:

                  >>> $pdos = DB::statement('select * from dbname.contentRepository limit 1')
                  IlluminateDatabaseQueryException with message 'SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: select * from dbname.contentRepository limit 1)'
                  

                  谢谢

                  推荐答案

                  好像可以添加

                  'options'   => [
                                  PDO::ATTR_EMULATE_PREPARES => true
                              ]
                  

                  在数据库配置中的 projectName/config/database.php 文件中.会是这样的:

                  Inside projectName/config/database.php file in DB configuration. It will be like this:

                  'mysql' => [
                      'driver'    => 'mysql',
                      'host'      => env('DB_HOST', 'localhost'),
                      'database'  => env('DB_DATABASE', 'forge'),
                      'username'  => env('DB_USERNAME', 'forge'),
                      'password'  => env('DB_PASSWORD', ''),
                      'charset'   => 'utf8',
                      'collation' => 'utf8_unicode_ci',
                      'prefix'    => '',
                      'strict'    => false,
                      'options'   => [
                          PDO::ATTR_EMULATE_PREPARES => true
                      ]
                  ],
                  

                  Laravel 5.1.希望对您有所帮助!

                  Laravel 5.1. Hope it will help!

                  我目前在 Laravel 8 上,这个解决方案仍然有效.

                  I'm currently on Laravel 8 and this solution is still working.

                  这篇关于Laravel:一般错误:1615 Prepared statement需要重新准备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <tbody id='5smJl'></tbody>
                  • <bdo id='5smJl'></bdo><ul id='5smJl'></ul>

                    <small id='5smJl'></small><noframes id='5smJl'>

                    <tfoot id='5smJl'></tfoot>
                        <i id='5smJl'><tr id='5smJl'><dt id='5smJl'><q id='5smJl'><span id='5smJl'><b id='5smJl'><form id='5smJl'><ins id='5smJl'></ins><ul id='5smJl'></ul><sub id='5smJl'></sub></form><legend id='5smJl'></legend><bdo id='5smJl'><pre id='5smJl'><center id='5smJl'></center></pre></bdo></b><th id='5smJl'></th></span></q></dt></tr></i><div id='5smJl'><tfoot id='5smJl'></tfoot><dl id='5smJl'><fieldset id='5smJl'></fieldset></dl></div>

                            <legend id='5smJl'><style id='5smJl'><dir id='5smJl'><q id='5smJl'></q></dir></style></legend>