「20210104用PHP程式列出selldb資料庫的custs資料表的所有資料錄(a1.php)」:修訂間差異

出自金門農工維基III
跳至導覽 跳至搜尋
無編輯摘要
行 1: 行 1:
==0: mysql命令列操作==
C:\Users\user>mysql -p -uroot
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
<pre>
mysql> use selldb;
Database changed
mysql> desc custs;
+--------+----------+------+-----+---------+-------+
| Field  | Type    | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| id    | char(10) | YES  |    | NULL    |      |
| name  | char(20) | YES  |    | NULL    |      |
| amount | float    | YES  |    | NULL    |      |
| tel    | char(20) | YES  |    | NULL    |      |
+--------+----------+------+-----+---------+-------+
4 rows in set (0.07 sec)
mysql> select * from custs;
+-------+--------+--------+--------+
| id    | name  | amount | tel    |
+-------+--------+--------+--------+
| 10001 | 小狗  |    100 | 233111 |
| 20002 | 小貓  |    200 | 233444 |
| 30003 | 小牛  |    300 | 233777 |
+-------+--------+--------+--------+
3 rows in set (0.00 sec)
mysql> quit
Bye
C:\Users\user>
</pre>
==1: a1.php==
==1: a1.php==
<pre>
<pre>

於 2021年1月4日 (一) 06:54 的修訂

0: mysql命令列操作

C:\Users\user>mysql -p -uroot Enter password: ************ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use selldb;
Database changed
mysql> desc custs;
+--------+----------+------+-----+---------+-------+
| Field  | Type     | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| id     | char(10) | YES  |     | NULL    |       |
| name   | char(20) | YES  |     | NULL    |       |
| amount | float    | YES  |     | NULL    |       |
| tel    | char(20) | YES  |     | NULL    |       |
+--------+----------+------+-----+---------+-------+
4 rows in set (0.07 sec)

mysql> select * from custs;
+-------+--------+--------+--------+
| id    | name   | amount | tel    |
+-------+--------+--------+--------+
| 10001 | 小狗   |    100 | 233111 |
| 20002 | 小貓   |    200 | 233444 |
| 30003 | 小牛   |    300 | 233777 |
+-------+--------+--------+--------+
3 rows in set (0.00 sec)

mysql> quit
Bye

C:\Users\user>


1: a1.php

<body bgcolor=lightyellow>
<img src=dog.png width=50>
<hr color=red>
<?php
$con = mysqli_connect('localhost', 'root', 'abc123abc123', 'selldb');
$sql= "select id,name,amount,tel from custs";
$query     = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($query)){
        echo  $row['id'] . ":" . $row['name'] . ":" . $row['amount'] . "<br>";
	}
mysqli_close ($con);

?>
<hr color=green>
<img src=cat.png width=50>
</body>

2:result HTML

<body bgcolor=lightyellow>
<img src=dog.png width=50>
<hr color=red>
10001:小狗:100<br>20002:小貓:200<br>30003:小牛:300<br><hr color=green>
<img src=cat.png width=50>
</body>