dongzhiyan5693 2015-09-18 17:35
浏览 77
已采纳

使用Oracle和PHP插入数据或创建表或更新数据时出现问题

I'm new in PHP. I'm trying to insert data into the table. while running the program it's showing successful but when checking in oracle 10g database it's showing no data found. Same thing happened when creating table,it's showing table or view doesn't exist.

Here is my code=

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<h1><u>Inserting data into Table</u></h1>

<?php
// Create connection
$conn = oci_connect('SYSTEM', 'xxxx', 'localhost/XE');
// Check connection
if (!$conn) {
    die("Connection failed: " . oci_error());
}


$sql = "insert into MYGUESTS (ID, FIRSTNAME, LASTNAME, EMAIL) values (12, 'John', 'Doe', 'john@example.com')";
$stid=oci_parse($conn, $sql);
if(!$stid){
$e=oci_error($conn);
trigger_error(htmlentities($e[message],ENT_QUOTES),E_USER_ERROR);
}
else
 {
    echo "Successfull";
 }
oci_close($conn);
?>
</body>
</html>

why i can't see any data in oracle database? where is the problem?

  • 写回答

1条回答 默认 最新

  • doulun0651 2015-09-22 08:33
    关注

    You are missing commit and execute

    An OCI example from php.net:

    <?php
    
    // Insert into several tables, rolling back the changes if an error occurs
    
    $conn = oci_connect('hr', 'welcome', 'localhost/XE');
    
    $stid = oci_parse($conn, "INSERT INTO mysalary (id, name) VALUES (1, 'Chris')");
    
    // The OCI_NO_AUTO_COMMIT flag tells Oracle not to commit the INSERT immediately
    // Use OCI_DEFAULT as the flag for PHP <= 5.3.1.  The two flags are equivalent
    $r = oci_execute($stid, OCI_NO_AUTO_COMMIT);
    if (!$r) {    
        $e = oci_error($stid);
        trigger_error(htmlentities($e['message']), E_USER_ERROR);
    }
    
    $stid = oci_parse($conn, 'INSERT INTO myschedule (startday) VALUES (12)');
    $r = oci_execute($stid, OCI_NO_AUTO_COMMIT);
    if (!$r) {    
        $e = oci_error($stid);
        oci_rollback($conn);  // rollback changes to both tables
        trigger_error(htmlentities($e['message']), E_USER_ERROR);
    }
    
    // Commit the changes to both tables
    $r = oci_commit($conn);
    if (!$r) {
        $e = oci_error($conn);
        trigger_error(htmlentities($e['message']), E_USER_ERROR);
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序