| |
- MySQL
https://cc.applymail.com/phpmyadmin/
เรามีการ Backup MySQL ทุกสัปดาห์
- วิธี Connect MySQL ด้วย Perl
#!/usr/bin/perl
use DBI;
print "content-type: text/html\n\n";
$name="jack";
$phone="023216541";
# ใส่ข้อมูล (INSERT)
&openMySql;
&command("insert into table(id,name,phone) values('','$name','$phone')");
&closeMySql;
# แสดงข้อมูล (SELECT)
&openMySql;
&command("select * from table");
while(@field=$sth->fetchrow_array){
print "$field[0] | $field[1]<br>\n";
}
&closeMySql;
$new_phone="023216549";
# ปรับปุรง (UPDATE)
&openMySql;
&command("update table set phone='$new_phone' where
name='$name'");
&closeMySql;
# ลบข้อมูล (DELETE)
&openMySql;
&command("delete from table where name='$name'");
&closeMySql;
#############################################################
sub openMySql{
$dbh=DBI->connect("DBI:mysql:username:localhost:3306","username","password");
}
sub command{
my($sqlstatement)=@_;
$sth=$dbh->prepare($sqlstatement);
$sth->execute;
}
sub closeMySql{
$sth->finish;
$dbh->disconnect;
}
|
- วิธี Connect MySQL ด้วย PHP
$name="jack";
$phone="023216541";
# ใส่ข้อมูล (INSERT)
mysql_connect("localhost",username,password);
mysql_db_query("username","insert
into table(id,name,phone) values('','$name','$phone')");
mysql_close();
# แสดงข้อมูล (SELECT)
mysql_connect("localhost",username,password);
$result=mysql_db_query("username","select
* from table");
$nf=mysql_num_fields($result);
$nrow=mysql_num_rows($result);
while($row=mysql_fetch_array($result)){
for($i=0;$i<$nf;$i++){
echo "$row[$i] | ";
}
echo "<br>\n";
}
mysql_close();
$new_phone="023216549";
# ปรับปุรง (UPDATE)
mysql_connect("localhost",username,password);
mysql_db_query("username","update
table set phone='$new_phone' where name='$name'");
mysql_close();
# ลบข้อมูล (DELETE)
mysql_connect("localhost",username,password);
mysql_db_query("username","delete
from table where name='$name'");
mysql_close();
# ไม่อนุญาตให้ใช้คำสั่ง mysql_pconnect() เนื่องจากจะทำให้สิ้นเปลืองทรัพยากรณ์ของระบบโดยรวม
|
|