SQL
CREATE PROCEDURE `my_sp`(
IN in_var VARCHAR(32),
OUT out_var VARCHAR(255)
)
BEGIN
/*This work OK*/
SELECT my_column INTO out_var FROM my_table WHERE my_column = in_var LIMIT 1;
/*This not work*/
SELECT * INTO out_var FROM my_table WHERE my_column = in_var LIMIT 1;
END;
PHP
$dbh = new PDO( $connection_params );
$sql = "CALL my_sp( :in_var , @outvar )";
$stmt = $dbh->prepare( $sql );
$stmt->execute( array( ':in_var' => $_POST['in_var'] ) );
$sql = "SELECT @outvar";
$query = $dbh->query( $sql );
$result = $query->fetchAll( PDO::FETCH_ASSOC );
当我尝试'SELECT * ...'然后在php var_dump($ stmt)中返回false;
我从MySQL开始,我不知道你是否不能在存储过程中进行这种类型的查询(SELECT *),或者它是别的什么?
答案 0 :(得分:2)
删除CREATE PROCEDURE `my_sp`(
IN in_var VARCHAR(32)
)
BEGIN
SELECT * FROM my_table WHERE my_column = in_var LIMIT 1;
END;
声明,您将能够获取所有列:
{{1}}
或者您可以为每列声明一个变量。