voila ou j'en suis
j'ai essaye de tenir compte (au mieux de mes capacites) des differentes remarques glanées dans les différents forums et ce que j'en retire
- à l'activation du module d'enregistrement 1 j'ai ce retour :
Fatal error: Uncaught TypeError: mysqli_query(): Argument #1 ($mysql) must be of type mysqli, PDO given in /home/u320889525/domains/............../public_html/.........php:25 Stack trace: #0 /home/u320889525/domains/........../public_html/............php(25): mysqli_query() #1 {main} thrown in /home/u320889525/domains/................./public_html/...........php on line 25
qui correspond a la ligne :
" mysqli_query($conn,'LOAD DATA LOCAL INFILE \'amazon-fours.csv\' INTO TABLE produits ";
si je desactive cette ligne j'ai ce retour :
Parse error: syntax error, unexpected identifier "TERMINATED" in /home/u320889525/domains/.........../public_html/............php on line 27
- à l'activation du module d'enregistrement 2 j'ai ce retour :
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '':name' = ?, ':description' = ?, ':price' = ?' at line 3 in /home/u320889525/domains/.............../public_html/..................php:41 Stack trace: #0 /home/u320889525/domains/................fr/public_html/.................php(41): PDO->exec() #1 {main} thrown in /home/u320889525/domains/............../public_html/............php on line 41
qui correspond à la ligne :
$conn->exec($sql);
- à l'activation du module d'enregistrement 3 j'ai ce retour :
Fatal error: Uncaught Error: Object of class PDO could not be converted to string in /home/u320889525/domains/............../public_html/...........php:49 Stack trace: #0 /home/u320889525/domains/............/public_html/...............php(49): PDOStatement->execute() #1 {main} thrown in /home/u320889525/domains/................/public_html/.............php on line 49
qui correspond à la ligne
$req->execute([$conn]);
et j'ai du desactiver $price sinon j'ai cette erreur :
Warning: Uninitialized string offset 2 in /home/u320889525/domains/........../public_html/................php on line 47
répétée 10 fois
Code : Tout sélectionner
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$filename = 'amazon-fours.csv';
// The nested array to hold all the arrays
$the_big_array = [];
// Open the file for reading
if (($h = fopen("{$filename}", "r")) !== FALSE)
{
// Each line in the file is converted into an individual array that we call $data
// The items of the array are comma separated
include("db_connect.php");
while (($data = fgetcsv($h, 0, ";")) !== FALSE)
{
// Each individual array is being pushed into the nested array
$the_big_array[] = $data;
foreach ($the_big_array as $table)
{
foreach ($table as $contenu )
{
/*
// module d'enregistrement #1
mysqli_query($conn,'LOAD DATA LOCAL INFILE \'amazon-fours.csv\' INTO TABLE produits;
FIELDS TERMINATED BY \';\'
ENCLOSED BY \'"\'
LINES TERMINATED BY \'\n\' ')
or die("Erreur mise à jour table : ".mysqli_error($conn));
*/ // module d'enregistrement #2 /* $sql = <<<SQL INSERT INTO produits SET ':name' = $contenu[0], ':description' = $contenu[1], ':price' = $contenu[2] SQL ; $conn->exec($sql); */ // module d'enregistrement #3 $name = $contenu[0]; $description = $contenu[1]; $price = $contenu[2]; $req = $conn ->prepare('INSERT INTO produits (name,description,price) VALUES ($name,$description)'); $req->execute([$conn]); } //fin foreach #2 } // fin foreach #1 } //fin while} // fin if $sh/* echo '<br/>name : <br/> '; echo $name ; echo '<br/>description : <br/>'; echo $description ; echo '<br/>price : <br/>'; echo $price ; echo '<br/>req : <br/>'; print_r($req); */ /* // afficher le code echo "<pre>"; var_dump($the_big_array); echo "</pre>"; */?>[code]
contenu db_connect.php :
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
try
{
$host = 'mysql:dbname=................;host=127.0.0.1';
$dsn = '............................."
$user = '............................';
$password = '...................';
$conn = new PDO($host, $user, $password);
// Activation des erreurs PDO
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// mode de fetch par défaut : FETCH_ASSOC / FETCH_OBJ / FETCH_BOTH
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
}
catch(PDOException $e) {
die('Erreur : ' . $e->getMessage());
}
?>
[/code]