Skip to content

Instantly share code, notes, and snippets.

@stealth35
Created April 27, 2011 15:10
Show Gist options
  • Save stealth35/944414 to your computer and use it in GitHub Desktop.
Save stealth35/944414 to your computer and use it in GitHub Desktop.
<?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