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 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决