14c02-2.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 37 行

PHP
37
字号
<?php// Open the database connectionif (!($db = oci_connect('GUEST', 'secret', 'SERVICE.NAME'))) {    // Handle errors    die('SQL ERROR: Connection failed: ' . oci_error());}// Switch to the appropriate schema that we want to deal with:$sql = 'alter schema set current_schema=SCHEMANAME';// Parse & Execute this statement:$stmt = oci_parse($db, $sql) or die ("SQL ERROR: " . oci_error($db));oci_execute($stmt) or die ("SQL ERROR: " . oci_error($stmt));// Prepare a SQL insert: assume we received the description from the user$desc = 'Mortising Machine';$escaped = str_replace("'", "''", $desc);$sql = "insert into TOOLS (DESC, QTY) values ('{$escaped}', 0)";// Do the insertion, making sure to commit afterwards!$stmt = oci_parse($db, $sql) or die ("SQL ERROR: " . oci_error($db));oci_execute($stmt) or die ("SQL ERROR: " . oci_error($stmt));oci_commit($db) or die ("SQL ERROR: " . oci_error($db));// Select data from the table:$sql = 'select ID, DESC from TOOLS order by ID asc';$stmt = oci_parse($db, $sql) or die ("SQL ERROR: " . oci_error($db));oci_execute($stmt) or die ("SQL ERROR: " . oci_error($stmt));// Read all the data back in as associative arrayswhile ($row = oci_fetch_assoc($stmt)) {    echo "{$row['id']}. {$row['desc']}<br />\n";}// Now close the connectionoci_close($db);?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?