简体   繁体   English

更新查询在Joomla中不起作用

[英]update query not working in joomla

I'm working on a joomla extension and I'm trying to update entries in my joomla extensions database table using the following code in my model: 我正在开发joomla扩展,并尝试使用模型中的以下代码更新joomla扩展数据库表中的条目:

$this->_db->setQuery(
    $this->_db->getQuery(true)
    ->update('#__my_table')
    ->set('position=position+1')
);
$dbres = $this->_db->result();

However it doesn't do anything and outputs no error (Development on and error reporting maximum in global config) 但是,它什么也不做,也不输出任何错误(全局配置中的最大开发和错误报告)

I entered the query directly in PHPmyAdmin: 我直接在PHPmyAdmin中输入查询:

UPDATE cprn7_my_table SET position=position+1

and it works without any problems. 它可以正常工作。 I read about quoting keys and values with $this->_db->quoteName() or so, but I can't find any examples for that with queries like SET position=position+1 but only SET position=$newval so I don't know exactly what to quote and how. 我读过有关用$this->_db->quoteName()左右引用键和值的信息,但是我找不到像SET position=position+1这样的查询但仅使用SET position=$newval这样的查询示例,所以我没有不知道确切引用什么以及如何引用。

//EDIT: Found the error, it has to be $this->_db->query() and not $this->_db->result() //编辑:发现错误,它必须是$this->_db->query()而不是$this->_db->result()

A few possibilities come to mind. 我想到了一些可能性。 The first is that the --safe-updates setting is enabled, preventing updates (and deletes) whose WHERE clause lacks a primary key column specification. 第一个是启用--safe-updates设置,以防止其WHERE子句缺少主键列规范的更新(和删除)。

phpMyAdmin may turn this setting off, while your default MySQL client settings (in my.cnf , under [client] ) may be enabling it. phpMyAdmin可能会关闭此设置,而您的默认MySQL客户端设置(在[client]下的my.cnf )可能会启用它。 You can use the show variables statement to discover the setting's value. 您可以使用show variables语句来发现设置的值。 Also, see this doc for more info: http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_safe-updates 另外,请参阅此文档以获取更多信息: http : //dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_safe-updates

A second thought: You can quote the column name using backticks, for example: 再想一想:您可以使用反引号将列名引起来,例如:

SET `position`=`position` + 1

However, if this still seems to have no effect, and, if you have an admin-level MySQL account for your server, you can turn the general log on, then run your query, then turn it off again, then examine your results. 但是,如果这似乎仍然没有效果,并且,如果您的服务器具有管理员级别的MySQL帐户,则可以打开常规登录,然后运行查询,然后再次将其关闭,然后检查结果。 See this doc for working with the --general-log and related settings: http://dev.mysql.com/doc/refman/5.5/en/query-log.html 有关使用--general-log和相关设置的信息, --general-log文档: http : --general-log

BTW, if your MySQL client provider (or Joomla, or any other tier in the mix) is setting --safe-updates using a SET command (ie, upon connecting), you will also see this as an executed statement in the general log. 顺便说一句,如果您的MySQL客户端提供程序(或Joomla或混合中的任何其他层)正在使用SET命令(即,在连接时)设置--safe-updates ,则您还将在常规日志中将其视为已执行的语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM