数据库未更新 [英] database not being updated

查看:65
本文介绍了数据库未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个 php 页面上遇到了一些问题,由于某种原因,当我运行它时,查询没有执行

I am having some trouble with this php page, for some reason when i run it the query is not executed

<html>
<?php   
$link = mysql_connect('localhost', 'root');
if (!$link) {

    die('Could not connect: ' . mysql_error());

}

    for($i = 0; $i<$_GET['count'];$i++)
    {
     $query ="UPDATE `TEST.table` SET `Lan_ID` = '".$_GET[$i.'LanID'].
             "', `Switching` = '".$_GET[$i.'Switching'].
             "',`Own` = '".$_GET[$i.'Own'].
             "',`Division` = '".$_GET[$i.'Division'].
             "',`Switch_Number` = '".$_GET[$i.'Switch_Number'].
             "', `Telecom_Circuit_number` = '".$_GET    [$i.'Telecom_Circuit_number'].
             "', `Transmitter_Frequency` = '".$_GET[$i.'Trasmitter_frq'].
             "', `Receiver_Frequency` = '".$_GET[$i.'Receiver_frq'].
             "',    `Band_width` = '".$_GET[$i.'Band_width'].
             "', `Channel` = '".$_GET[$i.'Channel'].
             "', `Equipment` = '".$_GET[$i.'Equipment'].
             "', `Power` = '".$_GET[$i.'Power'].
             "', `Line_designation` = '".$_GET[$i.'Line_designation'].
             "', `Voltage` = '".$_GET[$i.'Voltage'].
             "', `Phase` = '".$_GET[$i.'Phase'].
             "', `Modulate` = '".$_GET[$i.'Modulate'].
             "', `Terms` = '".$_GET[$i.'Terms'].
             "', `Trap` = '".$_GET[$i.'Trap'].
             "', `Ltunner` = '".$_GET[$i.'Ltunner'].
             "', `Link` = '".$_GET[$i.'Link'].
             "', `Comment` = '".$_GET[$i.'Comment']."'";
     $query = $query. " " . $_GET['where'.$i];
    mysql_query($query, $link);

    }
    ?>
</html>

但是,当我在 MYSQL 工作台上运行查询时,它确实执行并更新了数据,我试图弄清楚大约一个小时,但我没有找到任何东西,谢谢您的帮助

However, when i run the run the query on MYSQL workbench it does execute and it updates the data, i been trying to figure it out for about an hour and i have not found anything, Thank you for your help

推荐答案

请注意其他人提供的建议.

Please heed the advice others have provided.

强烈怀疑:

UPDATE `TEST.table` SET
        ^^^^^^^^^^

通常,我们不会在表名中使用句点作为字符.

Normally, we don't use a period as a character in a table name.

我怀疑您在这里想要的实际上是数据库的名称和表的名称.句点分隔符不会包含在反引号中,除非它实际上是表的名称.

I'm suspicious that what you wanted here was actually the name of a database, and the name of a table. The period delimiter does not get enclosed in the backticks, unless that is actually the name of the table.

UPDATE `TEST`.`table` SET
        ^^^^   ^^^^^  

这是我能想到的最可能的解释,为什么您在数据库表中没有看到任何行更新.

That's the most likely explanation I can think of as to why you aren't seeing any rows updated in your database table.

调试此类问题的最简单方法是在发送之前立即打印出将发送到 MySQL 的实际字符串.(或者,在开发时,而不是发送查询)

The simplest way to debug this type of issue is to print out the actual string that is going to be sent to MySQL, immediately before you send it. (Or, when developing, instead of sending the query)

echo $query;

另外,最好的做法是检查你执行的 SQL 语句是否抛出了错误,而不是拉着邪恶博士关上门,然后用手指指着嘴角说我"我只是假设一切都按计划进行.什么?"

Also, best practice is to check whether your execution of the SQL statement threw an error or not, rather than pulling a Dr. Evil shut the door and pinky-to-the-corner-of-the-mouth "I'm just gonna assume it all went to plan. What?"

同样,请注意其他人提供的建议.并提防小鲍比桌".

Again, please heed the advice others have provided. And beware of "Little Bobby Tables".

http://xkcd.com/327/

这篇关于数据库未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆