草庐IT

mysqli语句执行错误: Result consisted of more than one row

coder 2023-10-12 原文

我正在使用选择查询从 TUsers 获取三个值,其中出现错误

Mysqli 语句执行错误:结果包含多于一行。

我使用 DISTINCTROW 来避免重复,并且我使用 Zend 框架来调用该过程。

代码如下:

程序:

         CREATE DEFINER=`root`@`` PROCEDURE `spfetchloginid`(in securityans   varchar(50),out email varchar(50),out loginidout varchar(50),out useridout varchar(50))
         BEGIN

         SELECT DISTINCTROW Email,login_id,user_id into email,loginidout,useridout  FROM DB.TUsers where SecurityAns=securityans ;

         END

从 Controller 调用 ZendFramework 中的过程:

            $db=Zend_Db_Table::getDefaultAdapter();
        $spParams = array(1,'NewValue');
        $stmt = $db->query("CALL   spfetchloginid('$securityans',@email,@loginidout,@useridout)");

        print_r($stmt->fetchAll());
        $stmt->closeCursor();   

        $stmtresult10=$db->query("select @email");
        $email_to=$stmtresult10->fetch();
        $stmtresult10->closeCursor();
        $Emails=$email_to["@email"];
         echo $Emails;  

        $stmtresult11=$db->query("select @loginidout");
        $loginid=$stmtresult11->fetch();
        $stmtresult11->closeCursor();

        $loginids=$loginid["@loginidout"];
        echo $loginids; 

        $stmtresult12=$db->query("select @useridout");
        $userid=$stmtresult12->fetch();
        $stmtresult12->closeCursor();

        $userids=$userid["@useridout"]; 

        echo $userids;

在使用 Zend 和 My Sql 调用程序时,请告诉我任何好的建议。

最佳答案

来自 fine manual :

DISTINCT specifies removal of duplicate rows from the result set. [...] DISTINCTROW is a synonym for DISTINCT.

这么说吧:

SELECT DISTINCTROW Email, login_id, user_id
...
where SecurityAns = securityans

只是从结果集中删除重复项,但如果您有多行具有相同的 SecurityAns 并且它们都是 securityans,那么您的查询将返回多行。如果 SecurityAns 是对“你最喜欢的颜色是什么”或“你母亲的娘家姓是什么”之类的标准问题的回答,那么你应该期待很多重复,所以 SecurityAns 当然不足以保证唯一性。

您需要在 WHERE 子句中添加更多内容以保证唯一的结果。或者,您可以添加 LIMIT 1 但这只是解决实际问题的绷带。

您的 WHERE 子句也可能遇到问题:

where SecurityAns = securityans

表中的每一行都应该为真,因为我认为将使用 securityans 列名而不是 securityans 参数。尝试使用不同的参数名称。例如,我看到您的重复问题是这样的:

create procedure p(in id int, out result int)
begin
    select id into result from t where id = id;
end

但不是这个版本:

create procedure p(in find_id int, out result int)
begin
    select id into result from t where id = find_id;
end

关于mysqli语句执行错误: Result consisted of more than one row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10695773/

有关mysqli语句执行错误: Result consisted of more than one row的更多相关文章

  1. ruby-openid:执行发现时未设置@socket - 2

    我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass

  2. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  3. ruby - Chef 执行非顺序配方 - 2

    我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul

  4. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  5. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  6. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  7. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

    我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

  8. ruby - #之间? Cooper 的 *Beginning Ruby* 中的错误或异常 - 2

    在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee

  9. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  10. ruby - 为什么 Ruby 的 each 迭代器先执行? - 2

    我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试

随机推荐