MySQL/PHP更新查询错误

发布于 2024-09-16 19:01:31 字数 1974 浏览 2 评论 0原文

我正在运行一个查询来更新表中的一小部分“项目”,来自 PHP。 使用“Sequel Pro”运行代码可以完美执行它,而在 PHP 上使用 mysql(“query here”); 运行它。惨败。

我的查询有什么问题吗?

UPDATE `service_joblocation` 
   SET  `in_use` =  '1', 
        `in_use_since` =  '1283488686', 
        `in_use_currentcount` =  `in_use_currentcount`+1, 
        `in_use_historicalcount`= `in_use_historicalcount`+1 
  WHERE `id` = 5 
  LIMIT 1;

UPDATE `service_joblocation` 
   SET `in_use` =  '1', 
       `in_use_since` =  '1283488686', 
       `in_use_currentcount` = `in_use_currentcount`+1, 
       `in_use_historicalcount` = `in_use_historicalcount`+1 
 WHERE `id`=16 
  LIMIT 1;

UPDATE `service_joblocation` 
   SET  `in_use` =  '1', 
        `in_use_since` = '1283488686', 
        `in_use_currentcount` = `in_use_currentcount`+1, 
        `in_use_historicalcount` = `in_use_historicalcount`+1 
  WHERE `id`=18 
   LIMIT 1;

UPDATE `service_items` SET  `checkin_user`='9', `checkin_date`='1283488686', `location`='5' WHERE `id`=576;
UPDATE `service_items` SET  `checkin_user`='9', `checkin_date`='1283488686', `location`='16' WHERE `id`=577;
UPDATE `service_items` SET  `checkin_user`='9', `checkin_date`='1283488686', `location`='18' WHERE `id`=578;
UPDATE `service_jobs` SET `checkin_date`='1283488686', `checkin_user`='9',`checkin_department`='1',`checkin_client_person`='0', `items_x`=`items_x`+1 WHERE `id`='518' LIMIT 1;
UPDATE `service_jobs` SET `checkin_date`='1283488686', `checkin_user`='9',`checkin_department`='1',`checkin_client_person`='0', `items_x`=`items_x`+1 WHERE `id`='518' LIMIT 1;
UPDATE `service_jobs` SET `checkin_date`='1283488686', `checkin_user`='9',`checkin_department`='1',`checkin_client_person`='0', `items_x`=`items_x`+1 WHERE `id`='518' LIMIT 1;

这是输出消息...

您的 SQL 语法有错误; 检查对应的手册 您的 MySQL 服务器版本 在“更新”附近使用正确的语法 service_joblocation SET in_use = '1', in_use_since = '1283488686' 在 第 2 行

I'm running a query to update a small group of 'items' in a table, from PHP.
Running the code with "Sequel Pro" executes it perfectly, while running it on PHP using mysql("query here"); fails miserably.

Is there anything wrong with my query?

UPDATE `service_joblocation` 
   SET  `in_use` =  '1', 
        `in_use_since` =  '1283488686', 
        `in_use_currentcount` =  `in_use_currentcount`+1, 
        `in_use_historicalcount`= `in_use_historicalcount`+1 
  WHERE `id` = 5 
  LIMIT 1;

UPDATE `service_joblocation` 
   SET `in_use` =  '1', 
       `in_use_since` =  '1283488686', 
       `in_use_currentcount` = `in_use_currentcount`+1, 
       `in_use_historicalcount` = `in_use_historicalcount`+1 
 WHERE `id`=16 
  LIMIT 1;

UPDATE `service_joblocation` 
   SET  `in_use` =  '1', 
        `in_use_since` = '1283488686', 
        `in_use_currentcount` = `in_use_currentcount`+1, 
        `in_use_historicalcount` = `in_use_historicalcount`+1 
  WHERE `id`=18 
   LIMIT 1;

UPDATE `service_items` SET  `checkin_user`='9', `checkin_date`='1283488686', `location`='5' WHERE `id`=576;
UPDATE `service_items` SET  `checkin_user`='9', `checkin_date`='1283488686', `location`='16' WHERE `id`=577;
UPDATE `service_items` SET  `checkin_user`='9', `checkin_date`='1283488686', `location`='18' WHERE `id`=578;
UPDATE `service_jobs` SET `checkin_date`='1283488686', `checkin_user`='9',`checkin_department`='1',`checkin_client_person`='0', `items_x`=`items_x`+1 WHERE `id`='518' LIMIT 1;
UPDATE `service_jobs` SET `checkin_date`='1283488686', `checkin_user`='9',`checkin_department`='1',`checkin_client_person`='0', `items_x`=`items_x`+1 WHERE `id`='518' LIMIT 1;
UPDATE `service_jobs` SET `checkin_date`='1283488686', `checkin_user`='9',`checkin_department`='1',`checkin_client_person`='0', `items_x`=`items_x`+1 WHERE `id`='518' LIMIT 1;

This is the output message...

You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near 'UPDATE
service_joblocation SET in_use =
'1', in_use_since = '1283488686' at
line 2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

所有深爱都是秘密 2024-09-23 19:01:31

您只能将单个语句传递给 mysql_query()。

还有其他函数/方法,例如 mysqli::multi_query() 但不适用于旧的 mysql 扩展。

You can only pass a single statement to mysql_query().

There are other functions/methods like e.g. mysqli::multi_query() but not for the old mysql extension.

つ低調成傷 2024-09-23 19:01:31

您能否发布执行查询的 PHP 代码(我假设您的意思是 mysql_query())。乍一看,该查询看起来不错,但我认为它前面可能有一些不正确的内容,例如无意的引号或大括号。

Can you post the PHP code which executes the query (I assume you meant mysql_query()). The query looks fine to me at a glance, but I think it may be preceded by something that is incorrect, such as an unintentional quotation mark or a brace.

挽袖吟 2024-09-23 19:01:31

service_joblocation.in_use 和 service_joblocation.in_use_since 的数据类型是什么?如果它们是数字,请尝试删除引号,即

UPDATE `service_joblocation` 
SET  `in_use` =  1, 
     `in_use_since` =  1283488686, 
     `in_use_currentcount` =  `in_use_currentcount`+1, 
     `in_use_historicalcount`= `in_use_historicalcount`+1 
WHERE `id` = 5 
LIMIT 1;

What are the data types of service_joblocation.in_use and service_joblocation.in_use_since? if they are numbers, try removing the quotation marks, i.e.

UPDATE `service_joblocation` 
SET  `in_use` =  1, 
     `in_use_since` =  1283488686, 
     `in_use_currentcount` =  `in_use_currentcount`+1, 
     `in_use_historicalcount`= `in_use_historicalcount`+1 
WHERE `id` = 5 
LIMIT 1;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文