我正在使用Symfony 4,并且正在尝试从存储过程中获取结果,但是使用了学说却无法正常工作。 如果我使用PDO,它会工作。为什么?!!!
这是我的教义代码:
$conn = $this->getDoctrine()->getManager()->getConnection();
$out = 1;
$sql = 'EXEC SP_INSERT @IdTipoSuceso = ? , @Idprestador = 1 , @Descripcion = 1';
$stmt = $conn->prepare($sql);
$stmt->bindParam(1,$out, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,4000);
$stmt->execute();
$result = $stmt->fetchAll();
$stmt->closeCursor();
doctrine.yaml
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'sqlsrv'
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
这是我使用pdo的代码,它可以正常工作:
$pdo = new PDO( 'sqlsrv:Server=127.0.0.1,1433;Database=db', 'user', 'pw');
$query ='EXEC SP_INSERT @IdTipoSuceso = ? , @Idprestador = 1 , @Descripcion = 1';
$stmt = $pdo->prepare($query);
$out = 1;
$stmt->bindParam(1, $out, PDO::PARAM_INT | \PDO::PARAM_INPUT_OUTPUT, 200);
$stmt->execute();
$result = $stmt->fetchAll();
$stmt->closeCursor();
我需要在理论上做这件事。
答案 0 :(得分:1)
您为什么要使用fetchAll
?
只需使用类似的内容:
$query = 'exec INTAK_NOWY_KONTAKT @id_kontrahenta = ?, @nazwisko = ?, @imie = ?, @tel = ?, @e_mail = ?, @id_kontaktu = ?';
$params = array(
$id_kontrahenta, $nazwisko, $imie,
$tel, $e_mail, $id_kontaktu
);
$types = array(
SQLSRV_PARAM_IN, SQLSRV_PARAM_IN, SQLSRV_PARAM_IN,
SQLSRV_PARAM_IN, SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT
);
$con = $this->entityManager->getConnection();
return $con->executeQuery($query, $params, $types);