开发者

MySQL Stored Procedure that returns query result

Is it possible that a MySQL function/stored procedure returns a query result?

Because I want to have this on PHP:

SET @csum:=0; 

SELECT 
    datvalor AS 'Date', 
    company AS 'Company', 
    (@csum:=@csum + amount) AS 'Sum'
FROM tbl_test
ORDER BY datvalor

but PHP can´t run multiple lines, right?

I've searched but everyone says th开发者_如何学JAVAat a procedure can't return a table. How will you solve this?

I don't want to put the Sum calculation on php, the goal here is too generate everything on MySQL

Tks


No, PHP can run multiple lines query. You just to concatenate strings.

e.g.

$sql = "";

$sql .= "SELECT ";
 $sql .= "   datvalor AS 'Date', ";
 $sql .= "   company AS 'Company', ";
 $sql .= "   (@csum:=@csum + amount) AS 'Sum'";
$sql .= " FROM tbl_test";
$sql .= " ORDER BY datvalor";


After more research, I've found that the way is use mysqli (MySQL Improved) instead of mysql, just don't know the little details (yet)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜