如果PHP,PDO插入和更新stetement(PDO insert and update stetement with if PHP)
我的疑问是:
$select_userid_query = execute_pdo_query("SELECT user_id FROM users WHERE username='" . $_COOKIE['username'] . "'"); if ($select_userid_query == 0){ execute_pdo_query("INSERT INTO user_status (user_id,last_activity_time) VALUES ((SELECT user_id FROM users WHERE username='" . $_COOKIE['username'] . "'),NOW())" , array($user_id, $last_activity_time)); } else{ execute_pdo_query("UPDATE user_status SET user_id = (SELECT user_id FROM users WHERE username='" . $_COOKIE['username'] . "'),last_activity_time= NOW()", array($user_id, $last_activity_time)); }
我想验证数据库中是否有记录,如果没有插入,如果只是用新的
NOW()
更新时间NOW()
任何想法我的语法错误?
my queries are :
$select_userid_query = execute_pdo_query("SELECT user_id FROM users WHERE username='" . $_COOKIE['username'] . "'"); if ($select_userid_query == 0){ execute_pdo_query("INSERT INTO user_status (user_id,last_activity_time) VALUES ((SELECT user_id FROM users WHERE username='" . $_COOKIE['username'] . "'),NOW())" , array($user_id, $last_activity_time)); } else{ execute_pdo_query("UPDATE user_status SET user_id = (SELECT user_id FROM users WHERE username='" . $_COOKIE['username'] . "'),last_activity_time= NOW()", array($user_id, $last_activity_time)); }
i want to verify if there is a record in the database and if not insert and if there's just update the time of that with the new
NOW()
any ideas where's my error in the syntax?
原文:
最满意答案
我有一个相当复杂的应用程序,我已经做了两次(中止)尝试移植。 您的应用程序有几个部分需要更改,但我真正的问题是宝石兼容性。
简短的回答 - 如果你使用了很多第三方宝石,那么你应该等待。 如果你的应用程序相对纯净,那么它现在可能值得升级。
编辑:还有一件事要补充。 在开始移植之前,请确保您拥有一组强大的测试。 这将立即告诉你什么是有效的,什么不是,让你对你的港口充满信心。
I have a fairly complicated app that I've made two (aborted) attempts to port. There are several parts of your app that will need to be changed, although the real problem for me was gem compatibility.
Short answer - if you're using a lot of third party gems, then you should wait. If you're app is relatively pure, then its probably worth upgrading now.
Edit: one more thing to add. make sure you have a robust set of tests before you start porting. That will tell you instantly what's working and what's not, and give you confidence in your port.
相关问答
更多-
升级到Rails 4.2问题(Upgrading to Rails 4.2 issues)[2024-01-27]
OP的问题(和我的)是关于原型轨道宝石中的不兼容问题。 这可以通过直接从github使用原型轨道的“4.2”分支来解决。 修改您的Gemfile条目,如下所示: gem 'prototype-rails', github: 'rails/prototype-rails', branch: '4.2' 请注意,从Rails 5开始不支持prototype-rails gem,因此现在可以像删除此依赖项一样好。 The OP's issue (and mine) was to do with an incom ... -
升级到Rails 4.1.1后,我不确定为什么停止工作,但正如@steel建议的那样,它与辅助方法没有包含在我的特定控制器中有关。 添加include ApplicationHelper到我的控制器的顶部将起作用,我可能已经更进一步将它添加到ApplicationController类,因为我需要所有控制器可用的方法。 最后我选择了另一种解决方案: 首先,我将last_page_url从ApplicationHelper到ApplicationController类,以便我的所有控制器都可以访问它。 然后我 ...
-
其中一颗宝石正在使用它。 或者你,在其他控制器中。 将before_filter所有用法替换为before_action并祈祷所有的宝石都保持足够的能力,以便在出现错误之前进行相同的操作。 One of the gems is using it. Or you, in other controllers. Replace all your usages of before_filter to before_action and pray that all your gems are maintained e ...
-
升级到rails 5.2.0后,无法指定要测试的目录(Cannot specify directories for testing after upgrading to rails 5.2.0)[2022-02-05]
从rails -T您可以看到可用的任务。 这个问题的两个相关问题是 rails test # Runs all tests in test folder except system ones rails test:system # Run system tests only 从中我们可以看到rails test不会运行系统测试。 为此,您需要运行rails test:system ,iirc,您可以使用rails test:system test运行所有rails test:syst ... -
vestal_versions gem依赖于ActiveRecord 3.0 。 您需要在vestal_versions未指定vestal_versions gem的版本,或指定为2.0.0 ,然后: bundle update rails vestal_versions vestal_versions gem has dependency to ActiveRecord 3.0. You need to unspecify version of vestal_versions gem in your G ...
-
升级到Rails 5.1.4(Issue upgrading to Rails 5.1.4)[2023-07-08]
通过以下命令gem uninstall rails系统中安装的所有版本的rails : gem uninstall rails 它应该提示你下面的东西 选择gem卸载: 1. rails-4.2.6 2. rails-5.1.4 3.所有版本 选择选项“所有版本”并全部卸载 安装所需的导轨版本: gem install rails --version=5.1.4 rails -v 5.1.4 更新 :由于您提到使用bundle install ,请检查Gemfile中是否使用5.1.4指定了rails 。 ... -
这些轨道剧的情节对我帮助很大。 http://railscasts.com/episodes/279-understanding-the-asset-pipeline http://railscasts.com/episodes/282-upgrading-to-rails-3-1 http://railscasts.com/episodes/318-upgrading-to-rails-3-2 摘要: 设置你的Gemfile group :assets do gem 'sass-rails' ge ...
-
问题是铁路还原为2.3.5。 我不得不卸载rails并设置一个gemset,如下所述: 每次我关闭终端轨道默认从3.0.3恢复到2.3.5? The issue was that rails reverted back to 2.3.5. I had to uninstall rails and set up a gemset as described here: Every time I close terminal rails defaults back to 2.3.5 from 3.0.3?
-
Bootstrap Sprockets提供单独的Bootstrap组件,以便于调试。 再次阅读bootstrap-rubygem中的说明 ,你会发现没有假设是bootstrap-sprockets的导入。 // app/assets/stylesheets/application.scss @import "bootstrap-sprockets"; // Remove this line 然而,假设它是一个javascript需要它。 这可以替换为仅用于引导的需求,以便更快地进行编译(您目前正在进行编译) ...
-
考虑升级到Rails 3(Considering upgrading to Rails 3)[2023-06-20]
我有一个相当复杂的应用程序,我已经做了两次(中止)尝试移植。 您的应用程序有几个部分需要更改,但我真正的问题是宝石兼容性。 简短的回答 - 如果你使用了很多第三方宝石,那么你应该等待。 如果你的应用程序相对纯净,那么它现在可能值得升级。 编辑:还有一件事要补充。 在开始移植之前,请确保您拥有一组强大的测试。 这将立即告诉你什么是有效的,什么不是,让你对你的港口充满信心。 I have a fairly complicated app that I've made two (aborted) attempts ...