如何在php中调用存储过程

时间:2014-01-29 05:31:38

标签: php sql stored-procedures

我已经创建了这样的商店程序

delimiter //
create procedure tom()
begin
select name from table where id = 1 
end
//

我正在像这样调用这个商店程序

if($connection){
echo "connected";
$res = R::exec('call tom');
    var_dump($res);
}

查询正在执行但我无法获取该值 例如:此预期输出为tom(表中的名称,其中id = 1)              但我得到int(1) 这意味着查询正在执行,但我无法获取值,该怎么做?

5 个答案:

答案 0 :(得分:1)

试试这个......

<?php
$mysqli = new mysqli("example.com", "user", "password", "database");

$mysqli->multi_query("CALL YOURPROCEDURE()");


?>

答案 1 :(得分:1)

我发现R::exec只是执行查询。你必须使用它来获得多维数组。这是这个的链接。 redbean orm queries

R::getAll( 'call tom' );

答案 2 :(得分:1)

以下是有关如何在PHP中编写和执行存储过程的详细讨论。

试试this。它可能对你有帮助。

答案 3 :(得分:1)

从PHP调用存储过程

$dbms = 'mysql';

//Replace the below connection parameters to fit your environment

$host = '192.168.1.8'; // give host IP
$db = 'myDB';          // give your db name here
$user = 'myUser';      // give the username here to connect
$pass = 'myPass';      // give the password for the user
$dsn = "$dbms:host=$host;dbname=$db";

$cn=new PDO($dsn, $user, $pass);

$res=$cn->exec('call tom');
print_r($res);

有关详细信息,请访问How to write and call stored procedures in PHP

答案 4 :(得分:0)

这很简单。我想你很期待知道如何使用readbeanphp和amp;来调用商店程序。检索存储过程的结果。

它很简单。试试这个

$response    = R::getCol("CALL procesedure() ");
print_r($response);

它将返回结果。

相关问题