English 中文(简体)
Mysqli 语句执行错误 : 结果包含不止一行
原标题:Mysqli statement execute error : Result consisted of more than one row

我正使用选中的查询从 TUsers 中获取三个值 。

Mysqli 语句执行错误 : 结果由多个行组成 。

我使用DistintsROW来避免重复,我使用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

主计长在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 来通知程序时有什么好的建议。

最佳回答

http://dev.mysql.com/doc/refman//5.5/en/select.html" rel=“nofollow”>fine 手册:

DISTINCT 指定从结果集中删除重复行 。 [.] DISTINCTROW DISTINCT 的同义词。

因此,我这样说:

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

仅从结果集中删除重复内容, 但如果您有多个多行的同一种 SecurityAns , 而且它们都是 securityans , 那么您的查询将返回多行。 如果 SecurityAns 是“ 你最喜欢的颜色是什么” 或“ 你母亲的婚前姓氏是什么” 等标准问题的答案, 那么您应该期待很多重复内容, 所以 SecurityAns 肯定不足以保证独特性 。

您需要添加更多条款来保证独到的结果。 或者,您可以添加 LIMIT 1, 但这只是一个绷带在真正的问题上。

你可能还遇到一个问题 你的地方条款:

where SecurityAns = securityans

/ code 列名称,而不是 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
问题回答

Supposing that all records have the same value in column SecurityAns but different values for all other columns (usually each user has it s own email address, right?), no matter you use distinct or distinct row, your query will retrieve always more then one row. So saying this, how do you want to assign multiple values to out variables? In and out parameters in Mysql procedures are atomic variables that can only be given one and ONE ONLY value. If you want to query a table for more than one row and do something with the retrieved data, I suggest you to do that using PHP and forget MySql stored procedures.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签