Pemrograman internet mobile
1 / 26

Pemrograman Internet Mobile - PowerPoint PPT Presentation

  • Uploaded on

Pemrograman Internet Mobile. Antonius R.C, S.Kom, M.Cs PHP 2. Form. Form (2). PHP nya?. if (empty($_POST["keterangan"])) $ket.="keterangan masih kosong"; if (isset($ket)){ echo "Error :".$ket; exit; } echo "Jadi nama anda: ".$_POST["nama"]."<br>";

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Pemrograman Internet Mobile' - kathie

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Pemrograman internet mobile

Pemrograman Internet Mobile

Antonius R.C, S.Kom, M.Cs


Php nya
PHP nya?

if (empty($_POST["keterangan"]))

$ket.="keterangan masih kosong";

if (isset($ket)){

echo "Error :".$ket;



echo "Jadi nama anda: ".$_POST["nama"]."<br>";

echo "Alamat anda: ".$_POST["alamat"]."<br>";

echo "Password anda: ".$_POST["password"]."<br>";

echo "Jenis Kelamin anda: ".$_POST["gender"]."<br>";

echo "Hobi anda adalah: <br>";

Register global
Register Global

  • Maka kita tidak bisa melewatkan variabel secara langsung

  • $_GET[“varname”]

  • $_POST[“varname”]

  • $_SESSION[“varname”]

  • $_COOKIE[“varname”]

  • $_REQUEST[“varname”]

  • $_FILES[“varname”]


<? //berhasillogin.php


if (isset($_SESSION["user"])){

echo "Selamat datang ".$_SESSION["user"]." anda berhasil login<br>";

echo "<a href='logout.php'>logout</a>";

}else {

echo "Maaf anda tidak berhak mengakseshalaman ini !";



Menulis file
Menulis File



print "Writing to $filename<br>";

$fp = fopen($filename,w) or die("Couldn't

open $filename");

fwrite($fp,"Hello World \n");


print "Appending to $filename<br>";

$fp = fopen($filename,"a") or die("Couldn't

open $filename");

fputs($fp,"And another thing\n");



Deklarasi class
Deklarasi Class

<? //defineclass.php

$anton = new Person();


$rasmus = new Person();


echo $erick->getName()."\n";

echo $rasmus->getName();


<? //defineclass.php

class Person


private $name;

function setName($name)


$this->name = $name;


function getName()


return $this->name;




Mysql connect

  • mysql_connect(server, username, password)

    • connects to a MySQL server through a port

    • the default is the string "localhost:3306"

    • username is a string for the user name

    • password is a string for the password

    • returns FALSE on failure

  • Example

    • $db_link = mysql_connect("localhost:3306", "test", "123");

  • there is also the persistent mysql_pconnect

Mysql select db

  • mysql_select_db(name, link)

    • select a database given by the string name

    • the link is optional and specifies the open link value such as $db_link returned by a connect statement.

    • if not supplied the last opened link is used.

    • returns TRUE on success else FALSE

  • Example

    • mysql_select_db("web_db");

Mysql error

  • mysql_error(link)

    • Return an error string or error number

    • the link is optional

    • if not supplied the last opened link is used.

    • Empty string is returned if there is no error.

  • Example

    • mysql_error();

Mysql query

  • mysql_query(query, link)

    • make a select query (link is optional)

    • query is a string for the MySQL query

    • Don't end the query with a semi-colon

    • Return value is a resource identifier or FALSE if

  • the query is SELECT, SHOW or DESCRIBE

    • Example (select all rows of books table)

    • $query = "SELECT * FROM books";

    • $result = mysql_query($query);

Mysql query1

  • INSERT and UPDATE queries

    • for these queries a resource is not returned

    • TRUE is returned on success

    • FALSE is returned on failure

  • Example (describe the books table)

    • $query = "DESCRIBE books";

    • $status = mysql_query($query);

Menghubungkan php dengan mysql

  • Agar script PHP yang kita buat dapat berhubungan dengan database dari MySQL dapat menggunakan fungsi berikut ini:

  • File utama.php:


    function open_connection()






    $link=mysql_connect($host,$username,$password) or die ("Database tidak dapat dihubungkan!");


    return $link;



  • Isi dari variabel $host, $username, $password dan $databasename dapat disesuaikan sesuai dengan setting pada MySQL server yang ada.

Menghubungkan php dengan mysql1

  • Contoh: Menampilkan data yang telah dibuat dengan menggunakan script PHP.

  • File contoh13.php:


    // ----- ambil isi dari file utama.php


    // ----- hubungkan ke database


    // ----- menentukan nama tabel


    // ----- perintah SQL dimasukkan ke dalam variable string

    $sqlstr="select * from $tablename";

    // ------ jalankan perintah SQL

    $result = mysql_query ($sqlstr) or die ("Kesalahan pada perintah SQL!");

// ------ putus hubungan dengan database


// ------ buat tampilan tabel

echo("<table width=100% cellspacing=1 cellpadding=2 bgcolor=#000000>");

echo("<tr><td bgcolor=#CCCCCC>No</td><td bgcolor=#CCCCCC>Nama</td><td

bgcolor=#CCCCCC>E-Mail</td><td bgcolor=#CCCCCC>Alamat</td><td


// ------ ambil isi masing-masing record

while ($row = mysql_fetch_object ($result))


// ----- mengambil isi setiap kolom






// ------ menampilkan di layar browser

echo("<tr><td bgcolor=#FFFFFF>$nomor</td><td bgcolor=#FFFFFF>$nama</td><td

bgcolor=#FFFFFF>$email</td><td bgcolor=#FFFFFF>$alamat</td><td





Informasi kolom kolom tabel
Informasi kolom-kolom tabel

  • mysql_list_fields(database, table, link)

    • For a select query it retrieves information from given table in given database. link is optional

    • The returned resource can be used to obtain properties of the table such as names of the table columns and field type information

  • Example

    • $fields = mysql_list_fields("web_db","books");

Jumlah fields
Jumlah Fields

  • mysql_num_fields(result)

    • return the numbers of columns in a table

    • result is the resource returned by a call to the mysql_list_fields function

  • Example

    • $fields = mysql_list_fields("web_db", "books");

    • $num_columns = mysql_num_fields($fields);

Field name
Field name

  • mysql_field_name(result, index)

    • return the name of the table column whose position is given by index (0,1,...)

    • result is the resource returned by a call to mysql_list_fields

  • Example: the first column name

    • $fields = mysql_list_fields("web_db", "books");

    • $isbn = mysql_field_name($fields, 0);

Mysql fetch array

  • mysql_fetch_array(result)

    • combines mysql_fetch_row, mysql_fetch_assoc

    • returns row information as both an associative array and an indexed array

Beberapa fungsi lain
Beberapa fungsi lain

  • mysql_num_rows(result)

    • returns number of rows from a select query

    • result is the resource returned by the select query

  • mysql_affected_rows(result)

    • used after an INSERT, UPDATE, or DELETE query to return the number of rows affected

    • result is the resource returned

  • mysql_close(link)

    • close the database connection associated with the given link

    • doesn't do anything for persistent links.