chapter B

bawltherapistSoftware and s/w Development

Dec 13, 2013 (3 years and 10 months ago)

107 views

chapter
B
SQLite
SQLiteManager
SQLi t e
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:141
B-2
SQLite
PHP 5
SQL
92
PHP
MySQL
Access
SQL Server
PHP
SQLite
SQL
PHP 5
SQLite
SQLi t e
MySQL
2~3
SQLite
SQLite
SQL
DCL
SQLite
PHP
Web
Web
PHP
SQLite
SQLite
SQLite
http://www.sqlite.org/
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:142
B-3
WAMP5
SQLiteManager
SQLiteManager
SQLite
Web
SQLite
SQLi t e
SQLite
Views
Triggers
SQLite
SQLiteManager
SQLite
PHP
ChB-2.php
SQLite
ChB-2.php
Users.db
C:\wamp\www\AppB
Users.db
SQLite
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:143
B-4
PHP
ChB-2.php
B-3
SQLiteManager
SQLiteManager
Users.db
user
1.
WAMP5
SQLiteManager
SQLiteManager
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:144
B-5
2.
Name
SQLiteManager
Users
Path
SQLite
C:\wamp\www\AppB\Users.db
Upload Database
SQLite
3.
Save
Users.db
HTML
4.
Add==>Name
user
3
Execute
HTML
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:145
B-6
5.
phpMyAdmin
Field
Type
Length
Primary
userid CHAR 10
name VARCHAR 20
age INT N/A
6.
Enregistrer
Users.db
user
SQLiteManager
SQLite
SQLiteManager
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:146
B-7
1.
WAMP5
SQLiteManager
SQLiteManager
2.
Us e r s
u s e r
Insert
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:147
B-8
3.
Value
SQLiteManager
Save
4.
SQL
Display
SQLite
MySQL
ext/mysqli
MySQL SQLite
mysqli_connect() sqlite_open()
mysqli_close() sqlite_close()
mysqli_query() sqlite_query()
mysqli_fetch_array() sqlite_fetch_array()
mysqli_num_rows() sqlite_num_rows()
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:148
B-9
PHP
SQLite
sqlite_open()
$db = @sqlite_open("Users.db") or
die("
:
!<br>");
SQLi t e
SQLite
sqlite_close()
sqlite_close($db);
B-3-1
SQLiteManager
SQLite
PHP
SQL
SQL
SQL
$name = sqlite_escape_string("
");
$sql = "INSERT INTO user (userid,name,age) VALUES (";
$sql .= "'jane','". $name . "',25)";
sqlite_escape_string()
Escape
SQL
SQL
SQL
sqlite_query()
SQL
$result = sqlite_query($db, $sql);
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:149
B-10
$db
$sql
SQL
SQL
false
SQLite
SQL
$error = sqlite_last_error($db);
$errmsg = sqlite_error_string($error);
die("
: $error
: $errmsg <br>");
sqlite_last_error()
SQL
sqlite_error_string($error)
ChB-3-1.php
PHP
SQLite
SQL
PHP
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1410
B-11
01: <!--
ChB-3-1.php -->
02: <html>
03: <head><title>
</title></head>
04: <body>
05: <?
06: //
07: $db = @sqlite_open("Users.db") or
08: die("
:
!<br>");
09: $name = sqlite_escape_string("
"); //
10: $sql = "INSERT INTO user (userid,name,age) VALUES (";
11: $sql .= "'jane','". $name . "',25)";
12: //
SQL
13: if ( sqlite_query($db, $sql) ) {
14: echo "
SQLite
<br>";
15: }
16: else {
17: //
18: $error = sqlite_last_error($db);
19: $errmsg = sqlite_error_string($error);
20: die("
: $error
: $errmsg <br>");
21: }
22: //
23: sqlite_close($db);
24: ?>
25: </body>
26: </html>
7~8
sqlite_open()
9~11
SQL
13~21
if
sqlite_query()
SQL
false
18~20
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1411
B-12
23
sqlite_close()
B-3-2
SQL
PHP
SQLite
SQL
SELECT
$result = sqlite_query($db, $sql);
$sql
SQL
$result
sql i t e_num_rows()
$num_rows = sqlite_num_rows($result);
sql i t e_query()
sqlite_fetch_array()
while ($row = sqlite_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row["userid"] . "</td>";
echo "<td>".sqlite_escape_string($row[1])."</td>";
echo "<td>" . $row["age"] . "</td>";
echo "</tr>";
}
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1412
B-13
while
sqlite_fetch_array()
$row
ChB-3-2.php
PHP
SQLite
SQL
01: <!--
ChB-3-2.php -->
02: <html>
03: <head><title>
SQL
</title></head>
04: <body>
05: <table border="1">
06: <tr><td>
</td><td>
</td><td>
</td></tr>
07: <?
08: //
09: $db = sqlite_open("Users.db");
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1413
B-14
10: $sql = "SELECT * FROM user"; //
SQL
11: //
SQL
12: $result = sqlite_query($db, $sql);
13: //
14: $num_rows = sqlite_num_rows($result);
15: //
16: while ($row = sqlite_fetch_array($result)) {
17: echo "<tr>";
18: echo "<td>" . $row["userid"] . "</td>";
19: echo "<td>".sqlite_escape_string($row[1])."</td>";
20: echo "<td>" . $row["age"] . "</td>";
21: echo "</tr>";
22: }
23: //
24: sqlite_close($db);
25: ?>
26: </table>
27:
: <? echo $num_rows ?><br>
28: </body>
29: </html>
10
SQL
12
sqlite_query()
SQL
14
16~22
while
sqlite_fetch_array()
18~20
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1414
B-15
B-3-3
PHP
SQLite
ext/mysqli
$db = sqlite_open($dbname) $db = new SQLiteDatabase($dbname)
sqlite_close($db) unset($db)
$result = sqlite_query($sql) $result = $db->query($sql)
$row = sqlite_fetch_array($result) $row = $result->fetch()
sqlite_num_rows($result) $result->numRows()
sqlite_escape_string()
ChB-3-3.php
PHP
ChB-3-2.php
SQLite
SQL
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1415
B-16
01: <!--
ChB-3-3.php -->
02: <html>
03: <head><title>
PHP
</title></head>
04: <body>
05: <table border="1">
06: <tr><td>
</td><td>
</td><td>
</td></tr>
07: <?
08: //
SQLite
09: $db = new SQLiteDatabase("Users.db");
10: $sql = "SELECT * FROM user"; //
SQL
11: //
SQL
12: $result = $db->query($sql);
13: //
14: $num_rows = $result->numRows();
15: //
16: while ($row = $result->fetch()) {
17: echo "<tr>";
18: echo "<td>" . $row["userid"] . "</td>";
19: echo "<td>" . $row[1] . "</td>";
20: echo "<td>" . $row["age"] . "</td>";
21: echo "</tr>";
22: }
23: //
24: unset($db);
25: ?>
26: </table>
27:
: <? echo $num_rows ?><br>
28: </body>
29: </html>
9
SQLiteDatabase
10
SQL
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1416
B-17
12
query()
SQL
14
numRows()
16~22
while
$result
fetch()
18~20
24
unset()
SQLiteDatabase
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1417
PHP5_ªþ¿ýB.p65 2005/4/19, ¤U¤È 02:1418