如何获得Oracle PHP返回ID

问题描述 投票:0回答:1

Oracle 12c + PHP

如何从此查询中获取ID:

$execute = "INSERT INTO DODATEK SELECT NVL(MAX(dodatekid),0)+1,'$randomString' from DODATEK";

我尝试过的oci_bind_by_name和RETURNING INTO

$c = oci_connect($username, $password, $database);
if (!$c) {
    $m = oci_error();
    trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
}

$executeforId = "INSERT INTO DODATEK SELECT NVL(MAX(dodatekid),0)+1,'$randomString' from DODATEK RETURNING dodatekid INTO :dodatekId";
$exForId = oci_parse($c,$executeforId);
oci_bind_by_name($stid, ':dodatekId', $dodatekIdForTxt);
echo $dodatekIdForTxt;

并且我得到警告:oci_bind_by_name():ORA-01036:非法变量名称/编号

php oracle oci
1个回答
1
投票

来自文档:

使用OUT绑定时必须指定maxlength,以便PHP分配足够的内存来保存返回的值。

因此,请尝试在绑定中添加maxlength和类型参数:

`oci_bind_by_name($exForId, ':dodatekId', $dodatekIdForTxt, -1, OCI_B_INT);`
© www.soinside.com 2019 - 2024. All rights reserved.