当前位置: 移动技术网 > IT编程>开发语言>PHP > 如何在PHP中使用Oracle数据库(3)

如何在PHP中使用Oracle数据库(3)

2019年05月20日  | 移动技术网IT编程  | 我要评论
利用 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为表单处理程序 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网