Php 2

582 views
528 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
582
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Php 2

  1. 1. PHP 2
  2. 2. What is Database?
  3. 3. A database is an organized collection of data forone or more purposes.
  4. 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. 5. Original Database
  6. 6. Relational Database use tables to storeinformationTables store data in a grid-like pattern ofcolumns and rows.
  7. 7. MySQL
  8. 8. SQL is the query language used to communicatewith a MySQL database.
  9. 9. Tool to manage MySQL
  10. 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. 11. CREATE DATABASE CREATE DATABASE elvis_store
  12. 12. CREATE TABLE INSIDE THE DATABASE CREATE TABLE email_list( first_name varchar(30), last_name varchar(30), email varchar(50) )
  13. 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. 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. 15. SELECT SELECT * FROM student SELECT first_name, last_name FROM student
  16. 16. WHERE Clause SELECT * FROM student WHERE first_name = “Dung”
  17. 17. UPDATE UPDATE student SET first_name = "Long" WHERE last_name = "Dung"
  18. 18. DELETE DELETE FROM student WHERE last_name = "Dung"
  19. 19. ORDER BY SELECT * FROM student ORDER BY last_name ASC SELECT * FROM student ORDER BY last_name DESC
  20. 20. Use PHP functions to talk to the database Connect to a database with the mysqli_connect() function.
  21. 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. 22. Use PHP functions to talk to the database Create an SQL query and store it as a string in a PHP variable.
  23. 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. 24. Use PHP functions to talk to the database Issue the query with the mysqli_query() function.
  25. 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. 26. Use PHP functions to talk to the database Close the database connection with the mysqli_close() function.
  27. 27. Use PHP functions to talk to the database Close the database connection with the mysqli_close() function. mysqli_close($con);

×