14c07-1.php

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

PHP
33
字号
<?php// Open the database connectionif (!($db = odbc_connect('datasource', 'guest_user', 'secret'))) {    // Handle errors    die('SQL ERROR: Connection failed: ' . odbc_errormsg());}// 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:if (!(odbc_exec($db, $sql))) {    // Give an error statement:    die('SQL INSERT ERROR: ' . odbc_errormsg($db) . " - Query was: {$sql}");}// Select data from the table:$sql = 'select id, desc from tools order by id asc';if (!($result = odbc_exec($db, $sql))) {    // Give an error statement:    die('SQL SELECT ERROR: ' . odbc_errormsg($db) . " - Query was: {$sql}");}// Read all the data back in as associative arrayswhile ($row = odbc_fetch_array($result)) {    echo "{$row['id']}. {$row['desc']}<br />\n";}// Now close the connectionodbc_close($db);?>

⌨️ 快捷键说明

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