如何使用PHP PDO运行Transact-SQL

时间:2021-09-13 12:38:32

I have a pl/sql script which is made up of multiple statments:

我有一个pl / sql脚本,它由多个语句组成:

SET @sql = NULL;

**Select values into variable**;

**Build a statment**;

**Prepare and execute statment**;

Run directly from the my-sql database this ouputs a standard table of results.

直接从my-sql数据库运行,这将输出一个标准的结果表。

But as I understand it, PDO has issues/limitations when it comes to running multiple statments and returns zero results for me, what would be the best way to return this queries results as a normal result set?

但据我了解,PDO在运行多个语句时会遇到问题/限制,并且对我来说返回零结果,将查询结果作为正常结果集返回的最佳方法是什么?

My experience with PDO has been limited to standard querires so i appologise if this is the wrong approach.

我对PDO的经验仅限于标准查询,所以如果这是错误的方法,我会道歉。

1 个解决方案

#1


0  

First how you can pl-sql statements on MySQL DB ?

首先,您如何在MySQL DB上使用pl-sql语句?

However If you have some MySQL statements, You can better create a MySQL Procedure and put code into that. Then call the procedure through PDO. Like following example from PDO Prepared Statments

但是,如果您有一些MySQL语句,您可以更好地创建MySQL过程并将代码放入其中。然后通过PDO调用该过程。如以下PDO Prepared Statments中的示例

$stmt = $dbh->prepare("CALL sp_returns_string(?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000); 

// call the stored procedure
$stmt->execute();

#1


0  

First how you can pl-sql statements on MySQL DB ?

首先,您如何在MySQL DB上使用pl-sql语句?

However If you have some MySQL statements, You can better create a MySQL Procedure and put code into that. Then call the procedure through PDO. Like following example from PDO Prepared Statments

但是,如果您有一些MySQL语句,您可以更好地创建MySQL过程并将代码放入其中。然后通过PDO调用该过程。如以下PDO Prepared Statments中的示例

$stmt = $dbh->prepare("CALL sp_returns_string(?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000); 

// call the stored procedure
$stmt->execute();