php - How to get the row of the last insert on Oracle using PDO? -
i need last row inserted using pdo in php. i've been searching , i've found pdo::lastinsertid doesn't work on oracle.
what alternatives have? other ways that? think current value of sequence (in table use sequence increment id) using pdo don't know if can.
update 1:
here's code.
static function insertarproveedor($name, $address, $phone, $email) { $con = conexionbd(); try { $stmt = $con->prepare("insert proveedores (nombre, direccion, telefono, email) values (?, ?, ?, ?) returning oid_proveedor :id"); $stmt->bindparam(1, $nombre); $stmt->bindparam(2, $direccion); $stmt->bindparam(3, $telefono); $stmt->bindparam(4, $correo); $stmt->bindparam('oid_proveedor', $id, pdo::param_int, 8); } catch (pdoexception $e) { echo "error".$e->getmessage(); } return $id; }
i got following message error:
errorsqlstate[hy093]: invalid parameter number: mixed named , positional parameters
notice: undefined variable: id in d:\xampp\htdocs\gestor\include\inserciones.inc on line 43
the line 43 return $id;
you can use oracle specific returning id var
method
$query = "insert employees (name) values ('jones') returning employee_no :employee_no"; $stmt = $pdo->prepare($query); $stmt->bindparam('employee_no', $employee_no, pdo::param_int, 8); $stmt->execute();
then $employee_no
have last id.
Comments
Post a Comment