我如何通过 php 和 oracle 插入 id

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5685348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:21:28  来源:igfitidea点击:

how i can get inserted id by php and oracle

phporacle

提问by user700792

i know that its not first time someone ask this question, i look at questions in stakoverflow which covered same subject but they didnt give me what i need, my request is how can get inserted id by php and oracle i have table named USERS with 3 columns ID, USERNAME, PASSWORD so i neeed the inserted primary id

我知道这不是第一次有人问这个问题,我查看了 stakoverflow 中涵盖相同主题的问题,但他们没有给我我需要的东西,我的要求是如何通过 php 和 oracle 插入 id 我有一个名为 USERS 的表,其中包含 3列 ID、USERNAME、PASSWORD 所以我需要插入的主 ID

i know how make that by php + mysql

我知道如何通过 php + mysql 做到这一点

$insert = mysql_query("INSERT INTO USERS(USERNAME,PASSWORD)VALUES('{JOHN}','{1235}')");
if(!$insert){
die(mysql_error());
}
echo mysql_inserted_id();

please help me to do it in oracle i want do it with out use OCIBindByName

请帮我在 oracle 中做到这一点,我想在不使用 OCIBindByName 的情况下做到这一点

回答by Vladislav Rastrusny

OCILogon is a synonym for oci_connect. Please read manual first before saying "I don't use this" ;)

OCILogon 是 oci_connect 的同义词。在说“我不使用这个”之前,请先阅读手册;)

http://php.net/manual/en/function.ocilogon.php

http://php.net/manual/en/function.ocilogon.php

So the solution is here: Get the auto-generated ID after an insert

所以解决方案在这里: 在插入后获取自动生成的 ID

And I don't see why not to use OCIBindByName. There is nothing to love ;) Just use what's effective and easy.

我不明白为什么不使用 OCIBindByName。没有什么值得爱的 ;) 只使用有效且简单的方法。

回答by m.genova

Do you have think to use a Trigger "Before insert" on Oracle TABLE USERS and an Oracle Sequence to generate a unique number? Oracle Trigger Guideand Use of Oracle Sequences

您是否想过在 Oracle TABLE USERS 和 Oracle Sequence 上使用触发器“插入前”来生成唯一编号? Oracle 触发器指南Oracle 序列的使用

I think this a possible solution.

我认为这是一个可能的解决方案。

Bye

再见