pemrograman berbasis web.ppt...
TRANSCRIPT
Indra [email protected]
YM : indranug
PHPPHP adalah PHP: Hypertext Preprocessor
server-side scripting language, like ASPscripts dijalankan di server
Kenapa PHP Run on Linux, Unix ,WindowsMendukung banyak databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)Free from LicenseBanyak free resourceHosting di Linux & Unix lebih murah daripada di Windows
MySQLMySQL adalah sebuah database serverDapat dijalankan pada beberapa platform OSMendukung sytax standard SQLBebas & gratis digunakan dan didownloadDikelola menggunakan PHPMyAdmin
Yang DibutuhkanPHP Installer
http://www.php.net/downloads.phpMySQL Database
http://www.mysql.com/downloads/index.htmlWeb server (Apache, IIS) / Web hosting
http://httpd.apache.org/download.cgi (apache)Text Editor (Notepad, Wordpad, EditPlus dll)
Xampp (paket installasi)
PHPFirst Script :
Buat File *.phpBeri tag <?php …. ?>Test script :
<?phpinfo();?>
PHP SyntaxCetak tulisan di php
<?echo “Halo”;
?>
VariableTidak perlu deklarasiTidak perlu definisi tipe<?
$tulisan = “Halo”;$angka = 12;echo $tulisan;echo $angka;
?>
PHP & HTMLMenggabungkan PHP & HTML
<html><body>
<?phpecho "Hello World";?>
</body></html>
PHP OperatorsOperator Description Example Result
+ Addition x=2x+2
4
- Subtraction x=25-x
3
* Multiplication x=4x*5
20
/ Division 15/55/2
32.5
% Modulus (division remainder)
5%210%810%2
120
++ Increment x=5x++
x=6
-- Decrement x=5x--
x=4
PHP OperatosOperator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y
PHP SyntaxIf..Then..Else statement
if ($username == "webmaster") {echo "Please enter your password below";} else {echo "We are sorry but you are not a recognised user";}
While..loop statement$times = 5;$x = 0;while ($x < $times) {echo "Hello World";$x++;}
PHP SyntaxSwitch statement
switch (n){case label1:
code to be executed if n=label1;break;
case label2:code to be executed if n=label2;break;
default:code to be executed if n is different from both label1 and label2;
}
PHP FunctionBuilt in functionCreate new functionCreate new function with parameters
POST & GET MethodPOST method
Tidak terlihat oleh pengguna lainDapat membawa beberapa jenis tipe data
GET methodTerlihat oleh siapa saja (tampil di browser address bar)Memiliki nilai limit (max. 100 characters).
Form Handling
MySQLMySQL adalah sebuah database.Data disimpan dalam bentuk table.Table terdiri dari kolom (jenis data), dan baris (isi data).
MySQL Data TypeField Type Description
TINYINT Small Integer Number
SMALLINT Small Integer Number
MEDIUMINT Integer Number
INT Integer Number
VARCHAR Text (maximum 256 characters)
TEXT Text
MySQL QueryQuery adalah suatu perintah pertanyaan, atau permintaan
SampleSELECT * FROM tbl_name WHERE [condition]
MySQL SyntaxCREATE TABLE
CREATE TABLE [IF NOT EXISTS] tbl_name(create_definition,...) [table_options]
INSERTINSERT [INTO] tbl_name [(col_name,...)] {VALUES | VALUE} ({expr | DEFAULT},...)
UPDATEUPDATE table_references SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition]
PHP & MySQLKoneksi PHP ke MySQL
mysql_connect(localhost,$username,$password);mysql_close();
Pilih Database@mysql_select_db($database) or die( "Unable to select database");
Jalankan Perintahmysql_query($query);
Retreive Datamysql_fetch_row