du5407 2015-08-19 07:49
浏览 9
已采纳

更新未执行

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='';
$database_username='';
$database_password='';
$database_name='';

set_time_limit(1600);
$link = mysql_connect($servername, $database_username, $database_password);
//$link = mysql_connect('mysql5-6.240', 'vintagemvm75', 'pu1df4mu');
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");

}
?>
  • 写回答

1条回答 默认 最新

  • douji1999 2015-08-19 08:07
    关注

    You have not filled out your connection variables that are being passed to mysql_connect. Moreover, you are not even using mysql_select_db(), to connect to database. It should be something like:

    mysqli_select_db($link, $database_name);
    

    Otherwise, provide the database name in mysql_connect() in the following manner:

    $link = mysql_connect($servername, $database_username, $database_password, $database_name);
    

    You need to have these variables filled out in order to connect to the database:

    $servername='';
    $database_username='';
    $database_password='';
    $database_name='';
    

    You have commented out the lines where you hard-coded them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红