par
blinz » 16 juin 2015, 16:37
Alors je suis passé sur pdo comme tu m'as demandé.
J'ai 2 erreur à l'écran
Invalid parameter number: parameter was not defined in C:\wamp\www\csv\index.php on line 95
Array to string conversion in C:\wamp\www\csv\index.php on line 95
Est ce également suffisant pr pouvoir insérer mes chaines ou j'aurais
' Merci à vous.
Mon code:
<?php
include("include/variables.php");
// Connexion à la base
try
{
$bdd = new PDO('mysql:host=127.0.0.1;dbname=lasortie1', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$bdd->exec('SET NAMES utf8');
}
catch(PDOException $e)
{
exit($e->getMessage());
die();
}
$flux = simplexml_load_file('http://localhost/csv/zxpd_201506140442_3467_31592008.xml'); // Source du flux.xml
foreach ($flux->product as $item) {
$titre = $item->titre;
$price = $item->price;
$url_fnac = $item->url_fnac;
$date_debut_sortie = $item->date_debut_sortie;
$date_fin_sortie = $item->date_fin_sortie;
$street = $item->street;
$photo = $item->largeImage;
$genre = $item->merchantCategoryPath;
$type = array( // Spectacle
'POP|Pop-rock/Folk ' => 11, '12P|Pop-Rock/Musique électronique' => 18, '1MC|Musique/Concerts' => 11,
);
foreach ($type as $k => $v) {
}
// On fait un explode afin de récupérer ce qu'il nous interesse
$postcode = $item->extra2;
$pieces = explode(" ", $postcode);
// On attribut le département en fonction des 2 premiers chiffre du code postal
$departement = substr($postcode, 0, 2);
$region = regionIdByDepartement($departement);
// Attribution de la valeur id 99 pour la fnac
$id_simply_user = '99';
// On valide la sortie par default
$valide = '1';
// Insertion des sorties
$req = $bdd->prepare('INSERT INTO simply_user (id_simply_user,titre,price,photo,url_fnac,date_debut_sortie,date_fin_sortie,street,postcode,city,id_region,id_departements,id_type_loisirs,valide) VALUES (:id_simply_user,:titre,:price,:photo,:url_fnac,:date_debut_sortie,:date_fin_sortie,:street,:postcode,:city,:id_region,:id_departements,:id_type_loisirs,:valide)');
$req->execute(array(
'id_simply_user'=>$id_simply_user,
'titre'=>$titre,
'price'=>$price,
'photo'=>$photo,
'url_fnac'=>$url_fnac,
'date_debut_sortie'=>$date_debut_sortie,
'date_fin_ssrtie'=>$date_fin_sortie,
'street'=>$street,
'postcode'=>$pieces[0],
'city'=>$pieces[1],
'id_region'=>$region,
'id_departements'=>$departement,
'id_type_loisirs'=>$type,
'valide'=>$valide
)) or die('Problème lors de l\'insertion');
}
?>
Alors je suis passé sur pdo comme tu m'as demandé.
J'ai 2 erreur à l'écran
[b]Invalid parameter number: parameter was not defined in C:\wamp\www\csv\index.php on line 95[/b]
[b] Array to string conversion in C:\wamp\www\csv\index.php on line 95[/b]
Est ce également suffisant pr pouvoir insérer mes chaines ou j'aurais [b]'[/b] Merci à vous.
Mon code:
[php]<?php
include("include/variables.php");
// Connexion à la base
try
{
$bdd = new PDO('mysql:host=127.0.0.1;dbname=lasortie1', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$bdd->exec('SET NAMES utf8');
}
catch(PDOException $e)
{
exit($e->getMessage());
die();
}
$flux = simplexml_load_file('http://localhost/csv/zxpd_201506140442_3467_31592008.xml'); // Source du flux.xml
foreach ($flux->product as $item) {
$titre = $item->titre;
$price = $item->price;
$url_fnac = $item->url_fnac;
$date_debut_sortie = $item->date_debut_sortie;
$date_fin_sortie = $item->date_fin_sortie;
$street = $item->street;
$photo = $item->largeImage;
$genre = $item->merchantCategoryPath;
$type = array( // Spectacle
'POP|Pop-rock/Folk ' => 11, '12P|Pop-Rock/Musique électronique' => 18, '1MC|Musique/Concerts' => 11,
);
foreach ($type as $k => $v) {
}
// On fait un explode afin de récupérer ce qu'il nous interesse
$postcode = $item->extra2;
$pieces = explode(" ", $postcode);
// On attribut le département en fonction des 2 premiers chiffre du code postal
$departement = substr($postcode, 0, 2);
$region = regionIdByDepartement($departement);
// Attribution de la valeur id 99 pour la fnac
$id_simply_user = '99';
// On valide la sortie par default
$valide = '1';
// Insertion des sorties
$req = $bdd->prepare('INSERT INTO simply_user (id_simply_user,titre,price,photo,url_fnac,date_debut_sortie,date_fin_sortie,street,postcode,city,id_region,id_departements,id_type_loisirs,valide) VALUES (:id_simply_user,:titre,:price,:photo,:url_fnac,:date_debut_sortie,:date_fin_sortie,:street,:postcode,:city,:id_region,:id_departements,:id_type_loisirs,:valide)');
$req->execute(array(
'id_simply_user'=>$id_simply_user,
'titre'=>$titre,
'price'=>$price,
'photo'=>$photo,
'url_fnac'=>$url_fnac,
'date_debut_sortie'=>$date_debut_sortie,
'date_fin_ssrtie'=>$date_fin_sortie,
'street'=>$street,
'postcode'=>$pieces[0],
'city'=>$pieces[1],
'id_region'=>$region,
'id_departements'=>$departement,
'id_type_loisirs'=>$type,
'valide'=>$valide
)) or die('Problème lors de l\'insertion');
}
?>[/php]