programing

라라벨:일반적인 오류: 1615 준비된 스테이트먼트를 다시 준비해야 합니다.

firstcheck 2022. 10. 28. 21:07
반응형

라라벨:일반적인 오류: 1615 준비된 스테이트먼트를 다시 준비해야 합니다.

홈스테드 가상 머신(vagent)에서 라라벨의 마지막 버전(5.1)을 사용하고 있습니다.

로컬 mariaDB 서버에 프로젝트를 연결합니다.이 서버에는 테이블과 2db 뷰가 있습니다.

db-view 테이블에서만 선택했기 때문에 랜덤으로 다음 오류가 반환됩니다.

일반적인 오류: 1615 준비된 스테이트먼트를 다시 준비해야 합니다.

오늘부터 DB 뷰에서만 선택하면 항상 이 오류가 발생합니다.phpMyAdmin을 열고 동일한 선택을 하면 올바른 결과가 반환됩니다.

php artisan tinker에러가 됩니다.db-view는 1개입니다.

// Select one user from user table
>>> $user = new App\User
=> <App\User #000000006dc32a890000000129f667d2> {}
>>> $user = App\User::find(1);
=> <App\User #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 App\Source
=> <App\Source #000000006dc32a820000000129f667d2> {}
>>> $source = App\Source::find(1);
Illuminate\Database\QueryException 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의 mysqldump의 문제를 .table_definition_cache하지만 잘 될지는 확실치 않고 수정할 수도 없습니다.

이것은 라라벨 벌레의 일종입니까?

내가 그걸 어떻게 알아?


편집:

요청하신 대로 모델 소스 코드를 추가합니다.원천.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Source extends Model
{
    protected $table = 'sources';


    /*
    |--------------------------------------------------------------------------
    | FOREIGN KEYS
    |--------------------------------------------------------------------------
    */

    /**
     * 
     * @return [type] [description]
     */
    public function customersList(){
        return $this->hasMany("App\CustomerSource", "sourceId", "id");
    }


    /**
     * 
     * @return [type] [description]
     */
    public function issues(){
        return $this->hasMany("App\Issue", "sourceId", "id");
    }
}

편집 2:

mysqli를 사용하여 프로젝트에서 동일한 쿼리를 실행하면 다음과 같이 작동합니다.

$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개월이 지났지만, 난 여전히 거기에 있어.같은 에러가 발생했지만, 해결 방법을 찾을 수 없었다.나는 팅커에서 작은 해결책을 시도하기로 결심했지만 좋은 소식은 아니다.시도한 내용을 보고합니다.

먼저 테이블 모델을 가져옵니다.

>>> $user = \App\User::find(1);
=> App\User {#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",
   }

이제 뷰 테이블 모델을 가져옵니다.

>>> $ir = \App\ContentRepository::find(15);
Illuminate\Database\QueryException 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:

>>> $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:

>>> $ir = \App\ContentRepository::find(15);
Illuminate\Database\QueryException 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');
Illuminate\Database\QueryException 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

준비되지 않은 쿼리를 두 번째로 시도합니다.

>>> DB::unprepared('select * from dbname.contentRepository limit 1')
Illuminate\Database\QueryException 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()을 사용해 보십시오.

>>> DB::fetchAll('select * from dbname.contentRepository limit 1'); 
PHP warning:  call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Database\MySqlConnection' 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()을 시도합니다.

>>> $pdo::fetchAll('select * from dbname.contentRepository limit 1');
  [Symfony\Component\Debug\Exception\FatalErrorException]  
  Call to undefined method PDO::fetchAll()           

Try 스테이트먼트...:

>>> $pdos = DB::statement('select * from dbname.contentRepository limit 1')
Illuminate\Database\QueryException 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.phpDB 설정음음음같 뭇매하다

'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
    ]
],

라라벨 5.1도움이 되었으면 좋겠다!

편집: 현재 Larabel 8을 사용하고 있으며 이 솔루션은 아직 작동합니다.

수락된 답변의 코멘트에 따라 실행 중

SET GLOBAL table_definition_cache = 1024

문제를 해결했습니다.

https://mariadb.com/kb/en/library/server-system-variables/ #table_definition_cache

문서화된 MySQL 버그인 것 같습니다.

편집:

모델에서는 'id'를 기본 키로 사용하고 있습니까?기본 키가 있더라도 모델 내에서 명시적으로 기본 키를 설정하는 것이 좋습니다.

protected $primaryKey = 'id'; // If different than id, definitely need to set the column here

코멘트를 달아보실 수도 있습니다.hasMany()기능하고 다시 시도합니다.Laravel은 특히 매핑하려는 레코드가 많은 경우 eagerLoad에서 이상한 작업을 수행할 수 있습니다.

언급URL : https://stackoverflow.com/questions/31957441/laravel-general-error-1615-prepared-statement-needs-to-be-re-prepared

반응형