使用 Oracle 和 PHP 插入数据或创建 table 或更新数据时出现问题
Problems while Inserting data or create table or updating data using Oracle and PHP
我是 PHP 的新人。我正在尝试将数据插入 table。虽然 运行 该程序显示成功,但在 oracle 10g 数据库中检查时显示 未找到数据 。创建 table 时发生同样的事情,它显示 table 或视图不存在。
这是我的代码=
<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>
为什么我在oracle数据库中看不到任何数据?问题出在哪里?
您缺少 commit
和 execute
来自 php.net 的 OCI 示例:
<?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);
}
?>
我是 PHP 的新人。我正在尝试将数据插入 table。虽然 运行 该程序显示成功,但在 oracle 10g 数据库中检查时显示 未找到数据 。创建 table 时发生同样的事情,它显示 table 或视图不存在。
这是我的代码=
<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>
为什么我在oracle数据库中看不到任何数据?问题出在哪里?
您缺少 commit
和 execute
来自 php.net 的 OCI 示例:
<?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);
}
?>