14c06-2.php

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

PHP
36
字号
<?php// Open the database:if (!($db = sqlite_open('tools.db'))) {    // Handle errors    die('SQL ERROR: Open failed: ' .         sqlite_error_string(sqlite_last_error($db)));}// Prepare a SQL insert: assume we received the description from the user$desc = 'Mortising Machine';$escaped = sqlite_escape_string($desc);$sql = "insert into tools (desc, qty) values ('{$escaped}', 0)";// Do the insertif (!(sqlite_query($db, $sql))) {    // Give an error statement:    die('SQL ERROR: ' . sqlite_error_string(sqlite_last_error($db)) .         " - Query was: {$sql}");}// Select data from the table:$sql = 'select id, desc from tools order by id asc';if (!($result = sqlite_query($db, $sql))) {    // Give an error statement:    die('SQL ERROR: ' . sqlite_error_string(sqlite_last_error($db)) .         " - Query was: {$sql}");}// Read all the data back in as associative arrayswhile ($row = sqlite_fetch_array($result)) {    echo "{$row['id']}. {$row['desc']}<br />\n";}// Now close the connectionsqlite_close($db);?>

⌨️ 快捷键说明

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