Chaima Posted August 18, 2015 Share Posted August 18, 2015 Hello , I'm developing a script to update my database with a CSV file ! I got this error when I run it Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/vinem/www/batch/batch_stock.php on line 47 this is the code in question : <?php /*---------------------CONNEXION MYSQL----------------------*/ $servername=''; $database_username=''; $database_password=''; $database_name=''; set_time_limit(1600); $link = mysql_connect('', '', ''); if (!$link) { die('Connexion impossible : ' . mysql_error()); } echo 'Connecté correctement'; mysql_close($link); //$link = mysql_connect($servername,$database_username,$database_password) or die("Erreur de connexion au serveur"); //mysql_connect //mysql_select_db($link, $database_name) or die("Erreur de connexion à la BDD"); //old: mysql_select_db /*---------------------FIN CONNEXION MYSQL----------------------*/ /*---------------------RÉCUPÉRATION DU FICHIER STOCK et INITIALISATION----------------------*/ $fichier = file("../batch/export_solsys.csv"); $fp = fopen("../batch/export_solsys.csv","r"); $upc= ""; $stock=""; $ligne = 1; /*---------------------FIN RÉCUP----------------------*/ echo("Parcours du fichier...")."<br/>"; /*---------------------MISE A JOUR DU STOCK----------------------*/ while($tab=fgetcsv($fp,1000,';')) { $champs = count($tab);//nombre de champs dans la ligne en question $ligne++; $upc = $tab[0]; $stock = $tab[7]; $batch ="UPDATE declinaison_stock_produit SET stock='4' where upc = '56939'"; $requete = mysql_query($link, $batch); echo("Stock mis à jour "); echo("Fin de l'éxécution du batch"); } Link to comment Share on other sites More sharing options...
MrPhil Posted August 18, 2015 Share Posted August 18, 2015 I'm developing a script to update my database with a CSV file ! Are you aware of the osC add-on "Easy Populate"? It may well do for you what you need, and save you a lot of effort. I got this error when I run it Note that mysql_* is an obsolete library. Unless your system is so far out of date that you cannot use the mysqli_* library, you should think about using mysqli instead. mysql_close($link); ... $requete = mysql_query($link, $batch); Why are you closing the connection and then trying to use that $link? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.