Csv file data (lineid and usernamme) on EC2 is inserted into RDS with PHP.
I would like to confirm that the usage of baindvalue is correct.
As a premise, the csv file has been read, and the contents have been confirmed by debugging.
$file [0] contains lineid and $file [1] contains username.
The connection to DB has also been completed.
And when you run the code
"PHP Parse error: syntax error, unexpected end of file in /home/ec2-user/index.php on
line 40 "will come back.
I looked up and used it, but it's a good thing, but I can't use it.
Is it correct to recognize that the variable that stores the value I want to put in the second subtraction number of bindvalue?
I would appreciate any advice.
Read CSV file
try {
$file = new SplFileObject ('/ tmp/winneyuser.csv');
$file->setFlags (SplFileObject :: READ_CSV);
} catch (RuntimeException $e) {
throw $e;
}
Code
DB connection
try {
$pdo = new PDO (
'mysql: host = *********,
'************',
'***************',
[
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');
Import to DB using
bindvalue
$line_id = $file [0];
$username = $file [1];
foreach ($file as $files) {
$stmt = $pdo->prepare ("INSERT INTO users (line_id, name) VALUES (: lineid,: username)");
$stmt = $pdo->prepare ($sql);
$stmt->bindValue (': line_id', $line_id, PDO :: PARAM_STR);
$stmt->bindValue (': username', $username, PDO :: PARAM_STR);
$stmt->execute ();
$pdo->commit ();
}
-
Answer # 1
-
Answer # 2
What if you actually move it and check the behavior?
-
Answer # 3
It was a typo that erased the closing parenthesis of the try statement.
It was solved by adding.
Related articles
- php - i want to confirm the correct position of session_regenerate_id (true) by login authentication
- ruby - rspec that would be correct does not pass
- php - a new project is created in laravel 803 i would like to create it in 830
- php - i would like to know about relative paths
- php - i would like to know in which language this voting system can be done
- php - i would like to use gpio of raspberry pi on the web
- php - i would like to send the repeated contents in form
- php - i would like to know the wordpress development procedure on site
- php - javascript confirm doesn't work well
- php - woocommerce for japan: i would like to add the day of the week to the "date format" of the shipping method
- i want to display the number of correct answers on the php (or jquery)/quiz website
- i would like you to explain the parts that you could not understand in the php reference book
- i'm not sure if the third argument of php's bindvalue is typed reliably
- about the correct way to specify text acquisition in phpquery
- php - how to get the correct value from the $_post variable
- php - i would like to know how to get each past numerical value with "ahrefs api"
- php - i want to identify and correct the cause of the page feed error that occurs in wordpress
- php - i want to implement an editing function i would like advice
- php - i would like to know how this code works
- i would like to know the cause of the error php
- 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
- ruby on rails - i want to know the settings of auto scaling for automatic server recovery (maintaining the number of instances)
- 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
I think it is better to put the whole amount if it is this amount, because it will be difficult to see if it breaks down and put the continuous code or whether it is really moving code or reprint error.
For now, parseError is around here
↓
The rest
Is it around?
Basic measuresSyntax errors are easier to find in IDEs and editors, so
It is recommended to search with
PHP IDE
and prepare the development environment.