190 likes | 332 Views
PHP dan MySQL. Konten Web. Web Statis /flat pages halaman web yang dikirimkan ke user sama persis yang ada di server. dari waktu ke waktu isi web selalu sama contoh . HTML Dinamis isi berubah sepanjang waktu database contoh . PHP, ASP, coldfusion. Static web. Dynamic Web.
E N D
Konten Web • Web Statis/flat pages • halaman web yang dikirimkanke user samapersis yang adadi server. • dariwaktukewaktuisi web selalusama contoh. HTML • Dinamis • isiberubahsepanjangwaktu • database contoh. PHP, ASP, coldfusion
PHP MySQL • Saatinibanyakaplikasi web yang berbasis php-mysql • MySQL is free • MySQL adalah DB no 2 didunia yang banyakdipakai
MySQL Fact • MySQL is a database system used on the web • MySQL is a database system that runs on a server • MySQL is ideal for both small and large applications • MySQL is very fast, reliable, and easy to use • MySQL supports standard SQL • MySQL compiles on a number of platforms • MySQL is free to download and use • MySQL is developed, distributed, and supported by Oracle Corporation • MySQL is named after co-founder Monty Widenius's daughter: My
Cross Platform • PHP combined with MySQL are cross-platform(Andadapatmembuataplikasidi windows tetapidi hosting di server Unix)
Connect MySQL <?php $dbhost = “localhost”; $dbuser = “guest”; $dbpass = “guest123”; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db( 'test_db' ); mysql_close($conn); ?>
User Enterprise MySQL • Wikipedia,[12] • Google[13][14] • Facebook,[15][16][17] • Twitter,[18] • Flickr,[19] • YouTube.[20] Sumber. Wikipedia.org
SQL • SQL is a standard language for accessing databases. Contoh. SELECT * FROM Customers; //Pilihsemua pegawai daritabel customer
Some of The Most Important SQL Commands • SELECT - extracts data from a database • UPDATE - updates data in a database • DELETE - deletes data from a database • INSERT INTO - inserts new data into a database • CREATE DATABASE - creates a new database • ALTER DATABASE - modifies a database • CREATE TABLE - creates a new table • ALTER TABLE - modifies a table • DROP TABLE - deletes a table • CREATE INDEX - creates an index (search key) • DROP INDEX - deletes an index
Select data SELECT column_name,column_nameFROM table_name; SELECT * FROM table_name;
Menampilkannilaiunik SELECT DISTINCT column_name,column_nameFROM table_name;
Syarat SELECT column_name,column_nameFROM table_nameWHERE column_name operator value; Operator = Equal <> Not equal != > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Betweenan inclusive range LIKE Search for a pattern IN To specify multiple possible values for a column
SQL AND & OR Operators • SELECT * FROM CustomersWHERE Country='Germany'AND City='Berlin'; • SELECT * FROM CustomersWHERE City='Berlin'OR City='München'; • SELECT * FROM CustomersWHERE Country='Germany'AND (City='Berlin' OR City='München');
SQL ORDER BY • SELECT column_name,column_nameFROM table_nameORDER BY column_name,column_name ASC|DESC;
Connect MySQL <?php $con=mysqli_connect("example.com","peter","abc1 23","my_db"); // Check connection if (mysqli_connect_errno($con)) {echo "Failed to connect to MySQL: " . mysqli_connect_error(); }mysqli_close($con);?>
PHP Select <?php$con=mysqli_connect("example.com","peter","abc123","my_db");// Check connectionif (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }$result = mysqli_query($con,"SELECT * FROM Persons");while($row = mysqli_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br>"; }mysqli_close($con); ?>