php dbconnect new PDO pgsql host localhost port 5433 dbname MyDB user

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php
$dbconnect = new PDO("pgsql:host=localhost; port=5433; dbname=MyDB; user=postgres; password=paladin77");
$file = fopen("/Users/Koldan/Downloads/films.csv", 'r') or die ('cannot open file');
while (($data= fgetcsv($file,",")) !== false){
$formatedData = Array(pg_escape_string($data[0]),
pg_escape_string($data[1]),
pg_escape_string($data[2]),
pg_escape_string($data[3]),
pg_escape_string($data[4]),
pg_escape_string($data[5]),
pg_escape_string($data[6]),
pg_escape_string($data[7]));
$query = "INSERT INTO \"TableTest\" (title, description, director, actors, year, country, time, kinopoisk_id) VALUES ('$formatedData[0]', '$formatedData[1]', '$formatedData[2]','$formatedData[3]','$formatedData[4]','$formatedData[5]','$formatedData[6]','$formatedData[7]');";
printf($query);
$dbconnect->query($query);
}