樹心幽徑

« 20181222在Ubuntu1604裝webp程式庫以解決ImageMagick的編譯問題1;重裝ImageMagick7以解決semaphore編譯問題 | Main | 20181224設計PHP函數dumpTable來列出selldb資料庫的custs資料表的全部資料錄(a3.php) »

20181222建立selldb資料庫、建立custs資料表、加入資料錄至custs中、列出custs中的資料錄的PHP程式(a2.php)
2018/12/22,16:02

(1)code

<body bgcolor=LIGHTGREEN>
<?php$con = mysqli_connect('127.0.0.1', 'root', 'w1????xxx, 'selldb');if (!$con) { echo "Error"; exit(); }
$sql = 'drop DATABASE selldb;';if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql = 'CREATE DATABASE selldb default character set utf8;';if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql = 'use selldb;';if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql="CREATE TABLE custs (id char(10),name char(20),amount float,tel char(20))";if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql = 'set names utf8;';if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql="insert into custs(id,name,amount,tel) values ('10001','小草',1000,'08-233375');";if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql="insert into custs (id,name,amount,tel) values ('10002','天牛' ,3000,'03-933375');";if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql="insert into custs (id,name,amount,tel) values ('20002','天牛' ,3000,'03-933375');";if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
$sql="insert into custs (id,name,amount,tel) values ('30002','天牛' ,3000,'03-933375');";if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }

$sql= "select id,name,amount,tel from custs";if( $query= mysqli_query($con, $sql) ){ echo " $sql OK!<br> "; } else { echo " $sql Failure!<br> "; }
while ($row = mysqli_fetch_array($query)){        echo  $row['id'] . ":" . $row['name'] . ":" . $row['amount'] . "<br>";}
mysqli_close ($con);
?></body>

(2)excute

drop DATABASE selldb; OK!
CREATE DATABASE selldb default character set utf8; OK!
use selldb; OK!
CREATE TABLE custs (id char(10),name char(20),amount float,tel char(20)) OK!
set names utf8; OK!
insert into custs(id,name,amount,tel) values ('10001','小草',1000,'08-233375'); OK!
insert into custs (id,name,amount,tel) values ('10002','天牛' ,3000,'03-933375'); OK!
insert into custs (id,name,amount,tel) values ('20002','天牛' ,3000,'03-933375'); OK!
insert into custs (id,name,amount,tel) values ('30002','天牛' ,3000,'03-933375'); OK!
select id,name,amount,tel from custs OK!
10001:小草:1000
10002:天牛:3000
20002:天牛:3000
30002:天牛:3000

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType