0% found this document useful (0 votes)
65 views

Php-Mysql: Week 5 Dynamic Web Programming

The document discusses building web applications that connect to a database. It covers: 1. Creating a database and table with fields like ID, NIM, name, email. 2. Connecting to the database with PHP using mysqli including selecting the database. 3. Performing CRUD operations with SQL - INSERT to add data, SELECT to retrieve data, UPDATE to edit data, and DELETE to remove data. 4. Displaying retrieved data from a table on a web page by executing queries and using a while loop to fetch results. Students are assigned to create a database with a table for students, connect a PHP page to display the data, and submit the work.

Uploaded by

maryam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Php-Mysql: Week 5 Dynamic Web Programming

The document discusses building web applications that connect to a database. It covers: 1. Creating a database and table with fields like ID, NIM, name, email. 2. Connecting to the database with PHP using mysqli including selecting the database. 3. Performing CRUD operations with SQL - INSERT to add data, SELECT to retrieve data, UPDATE to edit data, and DELETE to remove data. 4. Displaying retrieved data from a table on a web page by executing queries and using a while loop to fetch results. Students are assigned to create a database with a table for students, connect a PHP page to display the data, and submit the work.

Uploaded by

maryam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

PHP- MySQL

Week 5

Dynamic Web Programming


5th semester
DATABASE REVIEW

Databases

TIMAJARMATAKSTUDY PEMROGRAMSWEB 2015-2016


DATABASE REVIEW

Databases

TIMAJARMATAKSTUDY PEMROGRAMSWEB 2015-2016


Implementation Example

  Login form
Retrieval of user login data in the database and match it with input data from the user
  List table
Display data in a table (ex: student list table)
  Details
Displays detailed data from a table (eg details of student biodata based on a
certain NIM)
Data Definition Language (DDL)

DDL is a command used to define


objects in the database such as
table, field etc. DataManipulation Language (DML)
DML is a SQL command that deals with the
Commands from the DDL group: manipulation or processing of data or records in
  View Databases (showdatabases) tables.

  make (create) Databases DML commands include:


  Using (use)Database   SELECT
  Delete (drop) Databases   INSERT
  UPDATE
  View Table (show tables)   DELETE
  Create Table (create table)
  View Table Structure (desc)
  Delete Table (drop table)
  Table Structure Modification (alter)
Data Definition Language (DDL) DataManipulation Language (DML)

  Creating Database   INSERT


create database name_database; insert into table_name values (isi_data);
Example:
or
create database informtika;
  Using Database
insert into table_name (field_name)
use name_database; values (data_data);
Example: Example:
use informatics; insert into student values
  Creating Tables
CREATE TABLE <table_name> ( <column_name>
('L01800012', 'Budi', 'A', 'Solo');
<data_type>(<data_length>) [UNIQUE] [NOT
NUL] [PRIMARY KEY] [DEFAULT<default_value>],
. . . );

Example:
create student table
(
NIM char(10) primary key,
name char(30) not null,
class char(30) not null,
address char(40) not null,
);

TIMAJARMATAKSTUDY PEMROGRAMSWEB 2015-2016


Web Application With Database
Step By Step To Build Web Application
Create Database, Table ( and Data) Create

File Connection (Select Database) Create

Query

Extensions:

MySQL

MySQLi
Connection files
DB server settings: Server, Username, Password

Syntax: mysqli_connect('server_name', 'mysql_user', 'mysql_pass');

<?php
$connect= mysqli_connect('localhost','root','pass'); if($connect){

echo "Connection Success"; }else { echo


“Connection Fail”;} ?>
Connection files
Setting / Select Database Syntax: mysqli_select_db
('database_name');

<?php
$select_db= mysql_select_db('project'); if($select_db){

echo "Database Success"; }else { echo


“Database File”;} ?>
Connect.php
<?php

$host = 'localhost';

$user = 'root';

$password = ''; //the password is empty string

$db = 'informatics';

mysqli_connect($host,$user,$password) or die("Not Connected To Database


Server");

mysqli_select_db($db) or die("Not Connected To Database"); ?>


DML - Insert
Code to Execute Query
mysqli_query('your_query');

<?php
$sql = "insert into student(nim,name) values('123','Budi')"; $query =mysqli_query($sql);
if($query){

echo "Query Success";


}else { echo “Query Fail”;} ?>
DML - Update
Code to Execute Query
mysqli_query('your_query');

<?php
$sql = “update student set name='Budi' where nim='123'”; $query =mysqli_query
($sql); if($query){

echo "Query Success";


}else { echo “Query Fail”;} ?>
DML - Delete
Code to Execute Query
mysqli_query('your_query');

<?php
$sql = “delete from student where nim='123'”; $query =
mysqli_query($sql); if($query){

echo "Query Success";


}else { echo “Query Fail”;} ?>
DML - Select
Code to Execute Query

while(mysqli_fetch_array(mysqli_query(“Your_Query”))){

//Your_Action

<?php
$sql = “select * from student where nim='123'”; $query =
mysqli_query($sql); While($row=mysqli_fetch_array($query))
{ echo “$row['nim'] $row['name']”;

}
?>
practice
1. Create a database that has a table ''students'' with the attribute: id int auto
increment
nim char 10
name varchar 100
email varchar 100
varchar 100
varchar 100 . image
1. Follow the Steps from the given tutorial module 5 so that the data in the student table can be
displayed in the browser using a connection to the database.
2. Put the results of the exercise in 1 folder, send it to OL with the name: NIM_class_modul5.zip / .rar
3. Due date: next week
END

You might also like