I want to read csv file information from a PHP file installed in EC2.
If i hit the global IP on the browser, there will be no error message in the PDO connection, so I think you can connect to the DB.
If the code for reading csv file is added, it cannot be read due to an error (HTTP ERROR 500).
Since I heard that reading is fast, I use the SplFileObject function.
I would appreciate any advice.
<? php
try {
$file = new SplFileObject ('/ home/ec2-user/winneyuser.csv', r);
$file->setFlags (SplFileObject :: READ_CSV);
} catch (RuntimeException $e) {
throw $e;
}
try {
$pdo = new PDO (
'mysql: dbname = DBname;host = database-1.cuiejdfzi0uf.ap-northeast-1.rds.amazonaws.com;charset = utf8mb4',
'username',
'pass',
[
PDO :: ATTR_ERRMODE =>PDO :: ERRMODE_EXCEPTION,
PDO :: ATTR_DEFAULT_FETCH_MODE =>PDO :: FETCH_ASSOC,
]
);
} catch (PDOException $e) {
header ('Content-Type: text/plain;charset = UTF-8', true, 500);
exit ($e->getMessage ());
}
header ('Content-Type: text/html;charset = utf-8');
Code
-
Answer # 1
-
Answer # 2
In the meantime, DB operations are not related to CSV reading, so how about executing with minimal code?
If you are using a framework, it is easier to isolate the problem if you consider running it with the minimum amount of code outside the framework and then incorporating it into the framework.
First, delete all other sources
setFlags (SplFileObject :: READ_CSV); } catch (RuntimeException $e) { throw $e; }
PHP manual
If you add error display and CSV reading code, and read the error, you will be able to make the minimum code.
How to check the minimum code without affecting the existing environmentsetFlags (SplFileObject :: READ_CSV); // Add code for CSV reading/displaying here } catch (Exception $e) { // display exceptions on the fly echo $e->getMessage (); echo PHP_EOL; echo $e->getTraceAsString (); exit (); }
The source code is
/home/ec2-user/read_csv.php
,
After logging in with ssh, if you dophp /home/ec2-user/read_csv.php
, you can execute the minimum code regardless of the framework and Apache settings, so start from there Debugging is easy.
Related articles
- javascript - i want to read a csv file and have openstreatmap display pins
- i want to read a csv file with python numpy
- python - i want to read a csv file and output it
- php - i want to be able to use the validate function
- i want to get the name of the laravel php zip file
- i want to be able to describe it in [php] functionphp
- php - about attachment of media files
- i want to pass the php path
- python - [django] read csv file from url
- c # - read csv file operation
- c # - i want to read an xml file and display it on the datagrid
- i want to read xml with python asynchronously
- php - i want to pass the image file to the server
- i want you to see the error contents of php
- php - regarding uploading xserver files
- php - url parameters? i want to get the slug name from
- i want to link vba python files
- php - i want to remove commas from the data in $this-> data
- php - regarding uploading files from html form tags
- how to read csv file as list type as tuple for each line in python
- javascript - i want to eliminate the full calender not being displayed when deploying on aws
- linux - the changed contents are not reflected in the web application
- amazon ec2 - are ec2 m5 instances and macbooks comparable in performance?
- amazon ec2 - is it possible to check the connection from the local project to the database created by rds of aws?
- amazon ec2 - existing key pair is not available when building a new aws
- amazon ec2 - i want to hide a specific aws resource on the list screen
- amazon ec2 - i want to send an email from a project deployed on ec2 instant using the email sending function
- linux - permissionerror: [errno 13] permission denied:'/usr/local/lib/python37' when pip install xxx is done on ec2
- how to upgrade joomla's php version
- python - i deployed a django project on ec2 but the static files don't load
It was solved by deleting the above -r!