Web Programming 1
Silabus
1. Pengenalan PHP 2. Dasar-dasar PHP
3. Variabel dan Operator PHP 4. HTTP Request
5. Struktur Kontrol/Percabangan 6. Perulangan, Array dan Fungsi 7. Pengenalan MySQL Database 8. Database Connection,
9. Login Session
10. Create, Read, Update & Delete Data (CRUD) 11. Final Project
Referensi
• Membangun Aplikasi WEB dengan PHP & MySQL for Windows, Rony Setiawan, Lentera Ilmu, Jakarta • Modul Praktikum Pemrograman
Web, Ong Lu Ya, Stikom Surabaya • PHP Tutorial, TutorialsPoint,
tutorialspoint.com
• Teach Yourself PHP 4 in 24 Hours, Matt Zandstra, SAMS
Tugas & Quiz
• Tugas dilaksanakan sebanyak 4 x
– 2 x secara individu (sebelum UTS) – 2 x kelompok (setelah UTS)
• Jawaban tugas dapat dikumpulkan melalui lembar
jawaban atau softcopy (file) disesuaikan dengan perintah tugasnya.
• Semua mahasiswa peserta matakuliah wajib
mengerjakan tugas walaupun pada saat diberikan tugas tidak hadir.
• Quiz dilaksanakan sebanyak 2 x
• Pelaksanaan quiz tidak terjadwal & sewaktu-waktu
• Mahasiswa yang mengikuti quiz hanya mahasiswa yang hadir saat pelaksanaan quiz
Tugas Kelompok
• Kriteria : Pembangunan aplikasi web berbasis PHP & MySQL
• Anggota tim : 3 orang
• Tools : PHP, MySQL, Notepad++, Dreamweaver
• Tiap tim membangun sistem yg berbeda berdasar tema yang akan diumumkan pada pertemuan pertama setelah UTS
• Target penilaian:
– Proses: analisis, desain, implementasi, testing, dll
– Produk: dokumentasi seluruh tahap, source code, materi presentasi, dll
About PHP
• PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
• PHP is a recursive acronym for "PHP: Hypertext Preprocessor". • PHP is a server side scripting language that is embedded in HTML.
• It is used to manage dynamic content, databases, session tracking, even build entire ecommerce sites.
• It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
• PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side.
• The MySQL server, once started, executes even very complex queries with huge result sets in record-setting time.
• PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. • PHP4 added support for Java and distributed object architectures (COM and
CORBA), making n-tier development a possibility for the first time. • PHP is forgiving: PHP language tries to be as forgiving as possible. • PHP Syntax is C-Like.
About PHP
• PHP (PHP: Hypertext Preprocessor) merupakan bahasa pemrograman yang mampu berjalan di server-side (berjalan pada server web atau CGI), berbeda dengan javascript yang normalnya berjalan pada client-side (berjalan pada browser).
• PHP merupakan turunan C, Java dan Perl, yang dibuat dengan
• bahasa C. PHP bertujuan melakukan preprocessing, menghasilkan halaman HTML yang dinamis untuk tiap client.
• Sebelum memulai membuat website dengan menggunakan PHP, kita membutuhkan web server, dan nantinya untuk menyimpan data tiap user secara terstruktur, kita membutuhkan database.
• Umumnya PHP dipaketkan dengan Apache (web server) dan MySQL (database), paket tersebut sering disebut dengan AMP.
• Beberapa contoh AMP adalah XAMPP, WAMPServer, VertrigoServ, LAMP, UniServer (Uniform Server), Server2Go dan WAMP.
• Adapun untuk praktikum di laboratorium komputer saat ini kita menggunakan XAMPP .
XAMPP Control Panel
Untuk seterusnya penamaan file menggunakan extension .php dan peletakan file akan disimpan ke dalam folder /htdocs
Sintaks Dasar PHP
Skrip PHP dimulai dengan <?php dan diakhiri dengan ?>
Skrip PHP juga dapat disisipkan ke dalam dokumen yang mengandung tag HTML,
Penulisan Komentar di PHP
• Komentar berguna untuk proses dokumentasi dan dipakai untuk mendeskripsikan skrip PHP yang ditulis
PHP is whitespace insensitive
• PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row.
• one whitespace character is the same as many such characters.
• For example, each of the following PHP statements that assigns the sum of 2 + 2 to the variable $four is
PHP is case sensitive
• PHP is a case sensitive language.
• Try out the following example:
Statements are expressions terminated
by semicolons
• A statement in PHP is any expression that is followed by a semicolon (;).
• Any sequence of valid PHP statements that is enclosed by the PHP tags is a valid PHP program.
• Here is a typical statement in PHP, which in this case assigns a string of characters to a variable called
Braces make blocks
• Although statements cannot be combined like expressions, you can always put a sequence of statements anywhere a statement can go by enclosing them in a set of curly
braces.
Braces make blocks
• Although statements cannot be combined like expressions, you can always put a sequence of statements anywhere a statement can go by enclosing them in a set of curly
braces.
About Variable in PHP
• The main way to store information in the middle of a PHP program is by using a variable.
• Here are the most important things to know about variables in PHP.
– All variables in PHP are denoted with a leading dollar sign ($). – The value of a variable is the value of its most recent assignment.
– Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.
– Variables can, but do not need, to be declared before assignment.
– Variables in PHP do not have intrinsic types - a variable does not
know in advance whether it will be used to store a number or a string of characters.
– Variables used before they are assigned have default values.
– PHP does a good job of automatically converting types from one to another when necessary.
Deklarasi Variabel
• Untuk pendeklarasian variabel pada PHP diawali dengan tanda $
Variable Data Types in PHP
• PHP has a total of eight data types which we use to construct our variables:
– Integers: are whole numbers, without a decimal point, like 4195. – Doubles: are floating-point numbers, like 3.14159 or 49.1.
– Booleans: have only two possible values either true or false. – NULL: is a special type that only has one value: NULL.
– Strings: are sequences of characters, like 'PHP supports string operations.'
– Arrays: are named and indexed collections of other values.
– Objects: are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
– Resources: are special variables that hold references to resources external to PHP (such as database connections).
Tipe Data Integer
• Integer merupakan sekumpulan bilangan tanpa koma (non decimal), aturan untuk tipe data integer :
– Harus minimal 1 digit (0 – 9).
– Tanpa mengandung koma atau tanda kurung. – Tidak mengandung titik desimal.
– Bisa bilangan positif atau negative
– Dispesifikasikan menjadi 3 format : decimal (10-based), hexadecimal (16-based diawali dengan 0x) atau octal
(8-based diawali dengan 0)
Tipe Data Double
• Double merupakan bilangan dengan menggunakan desimal atau bilangan dengan eksponensial.
Tipe Data Boolean
• Boolean hanya digunakan untuk menentukan true atau
false
Tipe Data NULL
• NULL merupakan tipe data khusus yang hanya memiliki satu nilai yaitu : NULL.
• Untuk memberikan sebuah variable nilai NULL, lakukan dengan sintaks berikut:
• Variabel yang telah diberi nilai NULL memiliki properties berikut :
– Ini mengevaluasi FALSE dalam konteks Boolean.
Tipe Data Strings
• String merupakan tipe data untuk karakter atau teks
Tipe Data Array
• Sebuah array menyimpan sekumpulan nilai yang bertipe data sama.
• Contoh penulisan tipe data array :
• var_dump() merupakan fungsi untuk mengembalikan tipe data dari variabel.
Tipe Data Objects
• Untuk tipe data ini dipakai untuk menyimpan informasi yang diberikan ke dalam suatu class.
Echo & Print
• Ada beberapa perbedaan antara echo dan print :
• echo – dapat mengeluarkan satu atau lebih string.
• print – hanya mengeluarkan satu string, dan selalu mengembalikan 1.
• Echo adalah bahasa konstruksi , dan dapat digunakan dengan atau tanpa tanda kurung : echo atau echo()
• Echo digunakan untuk menampilkan tulisan yang dapat disisipkan tag HTML, atau menampilkan variabel
Echo & Print
Echo & Print
• Print juga adalah bahasa konstruksi , dan dapat digunakan dengan atau tanpa tanda kurung : print atau print()
• Print digunakan untuk menampilkan tulisan dan teristimewa dapat digunakan untuk menuliskan sintax HTML di dalamnya, atau
menampilkan variabel
Print untuk Menampilkan String
Latihan
• Buatlah file php untuk menampilkan biodata Anda
menggunakan variable dengan tampilan akhir sebagai berikut:
Nama : (Nama Anda) Tempat Lahir : Tanggal Lahir : Alamat : Kota : Jenis Kelamin : Agama :
• Simpan file dengan nama Biodata.php di folder /htdocs • Tampilkan hasil di browser Anda