如何在PHP中使用Oracle数据库(3)
程序员文章站
2022-08-11 15:22:46
利用 ora 向数据表 'email_info' 输入数据 当用户浏览这段脚本时,显示一个由姓名、email输入域组成的表单;当用户添好数据点击提交时,脚本程序将把这姓名、...
利用 ora 向数据表 'email_info' 输入数据
当用户浏览这段脚本时,显示一个由姓名、email输入域组成的表单;当用户添好数据点击提交时,脚本程序将把这姓名、email保存到'email_info'数据表中。
相关php代码:
if ($submit == "click"){
// the submit button was clicked!
// get the input for fullname and email then store it in the database.
putenv("oracle_sid=orasid");
$connection = ora_logon ("username","password");
if ($connection == false){
echo ora_errorcode($connection).": ".ora_error($connection)."
";
exit;
}
$cursor = ora_open ($connection);
if ($cursor == false){
echo ora_errorcode($connection).": ".ora_error($connection)."
";
exit;
}
$query = "insert into email_info values ('$fullname', '$email')";
$result = ora_parse ($cursor, $query);
if ($result == false){
echo ora_errorcode($cursor).": ".ora_error($cursor)."
";
exit;
}
$result = ora_exec ($cursor);
if ($result == false){
echo ora_errorcode($cursor).": ".ora_error($cursor)."
";
exit;
}
ora_commit ($connection);
ora_close ($cursor);
ora_logoff ($connection);
}
else{
echo '
<form action=insert.php method=post>
请输入姓名
<input name=fullname></input>
请输入email地址
<input name=email></input>
<input name=submit type=submit value=click></input>
</form>
';
}
?>
对了,这段脚本必须存为insert.php,因为在调用的页面中指定insert.php为表单处理程序
当用户浏览这段脚本时,显示一个由姓名、email输入域组成的表单;当用户添好数据点击提交时,脚本程序将把这姓名、email保存到'email_info'数据表中。
相关php代码:
if ($submit == "click"){
// the submit button was clicked!
// get the input for fullname and email then store it in the database.
putenv("oracle_sid=orasid");
$connection = ora_logon ("username","password");
if ($connection == false){
echo ora_errorcode($connection).": ".ora_error($connection)."
";
exit;
}
$cursor = ora_open ($connection);
if ($cursor == false){
echo ora_errorcode($connection).": ".ora_error($connection)."
";
exit;
}
$query = "insert into email_info values ('$fullname', '$email')";
$result = ora_parse ($cursor, $query);
if ($result == false){
echo ora_errorcode($cursor).": ".ora_error($cursor)."
";
exit;
}
$result = ora_exec ($cursor);
if ($result == false){
echo ora_errorcode($cursor).": ".ora_error($cursor)."
";
exit;
}
ora_commit ($connection);
ora_close ($cursor);
ora_logoff ($connection);
}
else{
echo '
<form action=insert.php method=post>
请输入姓名
<input name=fullname></input>
请输入email地址
<input name=email></input>
<input name=submit type=submit value=click></input>
</form>
';
}
?>
对了,这段脚本必须存为insert.php,因为在调用的页面中指定insert.php为表单处理程序
下一篇: 通过html表格发电子邮件