Chaima Posted August 19, 2015 Share Posted August 19, 2015 Hello, I prepare a script which update the field "stock" in the database of my online shop. When I run it ther's no No errors who appears ! However no change occurs at the database So what can be the problem ! It can't access to the database because of it's name ? Any idea? Here is the code below : <?php /*---------------------CONNEXION MYSQL----------------------*/ $servername='mysql5-6.240'; $database_username='vintagemvm75'; $database_password='pu1df4mu'; $database_name='vintagemvm75'; set_time_limit(1600); $link = mysql_connect($servername, $database_username, $database_password, $database_name); //$link = mysql_connect('mysql5-6.240', 'vintagemvm75', 'pu1df4mu', 'vintagemvm75'); if (!$link) { die('Connexion impossible : ' . mysql_error()); } echo 'Connecté correctement'; //$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]; echo("upc: ").$upc."<br/>"; echo("stock: ").$stock."<br/>"; $batch = "SELECT stock FROM declinaison_stock_produit where upc = '56939'"; $requete = mysql_query($batch, $link); $batch1 ="UPDATE declinaison_stock_produit SET stock = '4' where upc = '56939'"; $requete1 = mysql_query($batch1, $link); echo("Stock mis à jour "); echo("Fin de l'éxécution du batch"); } ?> Link to comment Share on other sites More sharing options...
Chaima Posted August 19, 2015 Author Share Posted August 19, 2015 I found it ! I added this to my code so it could select the database after the access $db_selected = mysql_select_db('vintagemvm75', $link); if (!$db_selected) { die ('Impossible de sélectionner la base de données : ' . mysql_error()); } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.