简体   繁体   English

PDOException:SQLSTATE[HY000]:一般错误:7890 找不到文件

[英]PDOException : SQLSTATE[HY000]: General error: 7890 Can't find file

I am trying to run the following project我正在尝试运行以下项目

https://github.com/saeedvaziry/laravel-vue-polling-app.git'

i am following the project readme.md but i am getting a PDOException when i run我正在关注项目 readme.md 但我在运行时收到 PDOException

php artisan migrate:refresh --seed

My Question what is causing this error and how can i resolve it我的问题是什么导致了这个错误,我该如何解决它

Here is the cli output这是 cli 输出

 PDOException  : SQLSTATE[HY000]: General error: 7890 Can't find file 'C:UsersuserDesktoplaravel-vue-polling-appstorageips.csv'.

  at C:\Users\user\Desktop\laravel-vue-polling-app\database\seeds\IpAddressesTableSeeder.php:18
    14|         $ipsPath = storage_path('ips.csv');
    15|         $pdo = \DB::connection()->getPdo();
    16|         $pdo->exec("
    17|                         LOAD DATA LOCAL
  > 18|                                 INFILE '" . $ipsPath . "'
    19|                         INTO TABLE
    20|                                 `ip_addresses`
    21|                         FIELDS TERMINATED BY ','
    22|                         ENCLOSED BY '\"'

  Exception trace:

  1   PDO::exec("
                        LOAD DATA LOCAL
                                INFILE 'C:\Users\user\Desktop\laravel-vue-polling-app\storage\ips.csv'
                        INTO TABLE
                                `ip_addresses`
                        FIELDS TERMINATED BY ','
                        ENCLOSED BY '"'
                        LINES TERMINATED BY '
'
                        IGNORE 0 LINES;
        ")
      C:\Users\user\Desktop\laravel-vue-polling-app\database\seeds\IpAddressesTableSeeder.php:18

  2   IpAddressesTableSeeder::run()
      C:\Users\user\Desktop\laravel-vue-polling-app\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29

and here is the seeder file这是播种机文件

<?php

use Illuminate\Database\Seeder;

class IpAddressesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $ipsPath = storage_path('ips.csv');
        $pdo = \DB::connection()->getPdo();
        $pdo->exec("
            LOAD DATA LOCAL
                INFILE '" . $ipsPath . "'
            INTO TABLE
                `ip_addresses`
            FIELDS TERMINATED BY ','
            ENCLOSED BY '\"'
            LINES TERMINATED BY '\r\n'
            IGNORE 0 LINES;
        ");
    }
}

None of the files have been altered by me and is as is in the repo as far as i know据我所知,我没有更改任何文件,并且与回购中的文件相同

Windows uses \\ for the path separator, which is also the escape character in MySQL. Windows 使用\\作为路径分隔符,这也是 MySQL 中的转义字符。 When you pass C:\\Users\\user\\Desktop\\laravel-vue-polling-app\\storage\\ips.csv to MySQL, it thinks the single \\ is the escape character, not the path separator.当您将C:\\Users\\user\\Desktop\\laravel-vue-polling-app\\storage\\ips.csv给 MySQL 时,它认为单个\\是转义字符,而不是路径分隔符。 To fix this, do要解决此问题,请执行

$ipsPath = addslashes($ipsPath);

before you use it in your query.在您的查询中使用它之前。

As you can see如你看到的

PDOException : SQLSTATE[HY000]: General error: 7890 Can't find file ' C:UsersuserDesktoplaravel-vue-polling-appstorageips.csv '. PDOException :SQLSTATE[HY000]:一般错误:7890 找不到文件“ C:UsersuserDesktoplaravel-vue-polling-appstorageips.csv ”。 no directory separators ?没有目录分隔符?

did you try to use [ESCAPED BY 'char']您是否尝试使用[ESCAPED BY 'char']

Your seeder file $ips should be like你的种子文件 $ips 应该是这样的

$ipsPath = addslashes(storage_path('ips.csv'));
...
....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:未捕获的 PDOException:SQLSTATE[HY000]:一般错误 - Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error SQLSTATE[HY000]:一般错误:无法创建表 - SQLSTATE[HY000]: General error:Can't create table PDOException:SQLSTATE [HY000]:一般错误:3 写入文件“/tmp/MYHKgYpv”时出错(错误代码:28) - PDOException: SQLSTATE[HY000]: General error: 3 Error writing file '/tmp/MYHKgYpv' (Errcode: 28) 找不到表(SQLSTATE [HY000]:常规错误:1无此类表:用户) - Can't find table (SQLSTATE[HY000]: General error: 1 no such table: users) Symfony 错误:[PDOException] SQLSTATE[HY000] [2002] 没有这样的文件或目录 - Symfony Error: [PDOException] SQLSTATE[HY000] [2002] No such file or directory 需要帮助以查找错误SQLSTATE [HY000]:常规错误 - Need help to find error SQLSTATE[HY000]: General error Connection.php 第 358 行中的 PDOException:SQLSTATE[HY000]:一般错误:1364 字段“id”没有默认值 - PDOException in Connection.php line 358: SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value SQLSTATE [HY000]:一般错误 - SQLSTATE[HY000]: General error 致命错误:未被捕获的PDOException:SQLSTATE [HY000]:常规错误:提取模式要求在 - Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: fetch mode requires the classname argument in 为什么SQLSTATE [HY000]:一般错误? - Why SQLSTATE[HY000]: General error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM