• Like
Php 2
Upcoming SlideShare
Loading in...5
×
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
468
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. PHP 2
  • 2. What is Database?
  • 3. A database is an organized collection of data forone or more purposes.
  • 4. Where’s database data actually stored? Can Isee the files?Database data is typically stored in files on ahard disk although you could certainly look atthem.
  • 5. Original Database
  • 6. Relational Database use tables to storeinformationTables store data in a grid-like pattern ofcolumns and rows.
  • 7. MySQL
  • 8. SQL is the query language used to communicatewith a MySQL database.
  • 9. Tool to manage MySQL
  • 10. SQL can be divided into two parts Data Manipulation Language (DML) SELECT UPDATE DELETE INSERT INTO Data Definition Language (DDL) CREATE DATABASE ALTER DATABASE CREATE TABLE ALTER TABLE DROP TABLE CREATE INDEX DROP INDEX
  • 11. CREATE DATABASE CREATE DATABASE elvis_store
  • 12. CREATE TABLE INSIDE THE DATABASE CREATE TABLE email_list( first_name varchar(30), last_name varchar(30), email varchar(50) )
  • 13. We need to define our data When you create a table, you have to tell the MySQL server what type of data each column will hold. To create a table, you need to know what type of data is stored in each table column.
  • 14. INSERT INSERT INTO student VALUES (“Trung”,”Dung”,”tdung@gmail.com”) INSERT INTO student (first_name,last_name,email) VALUES (“Trung”,”Dung”,”tdung@gmail.com”)
  • 15. SELECT SELECT * FROM student SELECT first_name, last_name FROM student
  • 16. WHERE Clause SELECT * FROM student WHERE first_name = “Dung”
  • 17. UPDATE UPDATE student SET first_name = "Long" WHERE last_name = "Dung"
  • 18. DELETE DELETE FROM student WHERE last_name = "Dung"
  • 19. ORDER BY SELECT * FROM student ORDER BY last_name ASC SELECT * FROM student ORDER BY last_name DESC
  • 20. Use PHP functions to talk to the database Connect to a database with the mysqli_connect() function.
  • 21. Use PHP functions to talk to the database Connect to a database with the mysqli_connect() function. The location of the database (a domain name, an IPaddress or localhost) The name of your database Your username and password $con = mysqli_connect("localhost","root","","php")
  • 22. Use PHP functions to talk to the database Create an SQL query and store it as a string in a PHP variable.
  • 23. Use PHP functions to talk to the database Create an SQL query and store it as a string in a PHP variable. $query = "SELECT * FROM student";
  • 24. Use PHP functions to talk to the database Issue the query with the mysqli_query() function.
  • 25. Use PHP functions to talk to the database Issue the query with the mysqli_query() function. $result = mysqli_query($con, $query); while($row = mysqli_fetch_array($result)) { echo $row[first_name] . " " . $row[last_name]; echo "<br />"; }
  • 26. Use PHP functions to talk to the database Close the database connection with the mysqli_close() function.
  • 27. Use PHP functions to talk to the database Close the database connection with the mysqli_close() function. mysqli_close($con);