Created
April 27, 2011 15:10
-
-
Save stealth35/944414 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include '../inc/header_admin.php'; | |
if($_SERVER['SERVER_NAME'] == 'localhost') | |
{ | |
error_reporting(-1); | |
ini_set('mysql.trace_mode', true); | |
} | |
$filename = '../maj_dossier/EXPARTHQ.txt'; | |
if(false === file_exists($filename)) | |
{ | |
exit('file not found'); | |
} | |
$sql = <<<SQL | |
REPLACE INTO `types_produits` | |
(`ref_produit`, `marque`, `sous_marque`, `prix_u`) | |
VALUES (?, ?, ?, ?) | |
SQL; | |
$query = sprintf('PREPARE stmt FROM \'%s\'', mysql_real_escape_string($sql)); | |
mysql_query("PREPARE stmt FROM '$sql'"); | |
$fichier = fopen($filename, 'rb'); | |
$header = fgetcsv($fichier, 0, ';'); | |
do | |
{ | |
$data = array_combine($header, $row); | |
if($data['article'] != 'ARTMAG' | |
&& $data['produit'] != '10') | |
{ | |
continue; | |
} | |
echo 'Code article : ' , $data['code_article'] , '<br />'; | |
echo 'Description : ' , $data['description'] , '<br />'; | |
echo 'Description 2 : ' , $data['description2'] , '<br />'; | |
echo 'Prix : ' , $data['prix'] , '<br />'; | |
echo '<br />'; | |
$values = array( | |
$data['article'], | |
$data['produit'], | |
$data['description'], | |
$data['prix'], | |
); | |
foreach($values as $id => $value) | |
{ | |
$using[] = "@$id"; | |
$query = sprintf('SET @%s = %s', $id, mysql_real_escape_string($value)); | |
mysql_query($query); | |
} | |
$query = sprintf('EXECUTE stmt USING %s', implode(', ', $using)); | |
mysql_query($query); | |
} | |
while($row = fgetcsv($fichier, 0, ';')); | |
mysql_query('DEALLOCATE PREPARE stmt'); | |
fclose($filename); | |
include '../inc/footer_admin.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment