存儲過程我已創建存儲過程我打電話此存儲過程在PHP這樣如何調用PHP
if($connection){
echo "connected";
$res = R::exec('call tom');
var_dump($res);
}
執行查詢時,但我不能夠取值 例如:期望輸出爲tom
(表中的名稱,其中id = 1) 但我得到int(1)
這意味着查詢正在執行,但我是n能夠獲取價值,如何做到這一點?
存儲過程我已創建存儲過程我打電話此存儲過程在PHP這樣如何調用PHP
if($connection){
echo "connected";
$res = R::exec('call tom');
var_dump($res);
}
執行查詢時,但我不能夠取值 例如:期望輸出爲tom
(表中的名稱,其中id = 1) 但我得到int(1)
這意味着查詢正在執行,但我是n能夠獲取價值,如何做到這一點?
嘗試......
<?php
$mysqli = new mysqli("example.com", "user", "password", "database");
$mysqli->multi_query("CALL YOURPROCEDURE()");
?>
我發現R::exec
只是執行查詢。你必須使用它來獲得多維數組。這裏是這個鏈接。 redbean orm queries
R::getAll('call tom');
這裏是關於如何在PHP中編寫和執行存儲過程的詳細討論。
嘗試this。這可能對您有所幫助。
從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
那麼它很簡單。我想你很期待知道如何使用readbeanphp調用存儲過程&檢索存儲過程的結果。
其簡單。試試這個
$response = R::getCol("CALL procesedure() ");
print_r($response);
它會返回結果。
這裏我使用了R :: exec,因爲我使用的是redbean(ORM) –
$ res只是給出了布爾值,不管查詢是否執行。我不知道關於readbean orm,但是在php mysqli中你使用$ row = mysqli_fetch_assoc($ res)來完成它;這裏$行給你一個關聯數組 – bring2dip