Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Asukademy Php part5 - MySQLi CRUD

bblurock
January 21, 2015

Asukademy Php part5 - MySQLi CRUD

PHP MySQLi CRUD

bblurock

January 21, 2015
Tweet

More Decks by bblurock

Other Decks in Programming

Transcript

  1. Database TABLE How Does My Data Get Stored? Ans: tables

    Databases use a series of Tables to store the data. first name last name email Benson Lu llwbenson@g mail.com Cherry Lin cherry@gmail. com #__asukademy_users
  2. Database id How Do I Organize My Data? Ans: id

    For each record, we give a id first name last name email 1 Benson Lu llwbenson @gmail.co m 2 Cherry Lin cherry@g mail.com #__asukademy_users unique id (Primary key)
  3. Database One database may have multiple tables id first name

    last name email 1 Benson Lu llwbenson@ gmail.com 2 Cherry Lin cherry@gma il.com #__asukademy_users id city area 3 Taichung South 4 Taipei Xinyi #__asukademy_address
  4. Database Table may have relation with other tables id first

    name last name email addres s_id 1 Benso n Lu llwbenso n@gmail. com 4 2 Cherry Lin cherry@g mail.com 3 #__asukademy_users id city area 3 Taichung South 4 Taipei Xinyi #__asukademy_addresses
  5. Create your Database Plan your table 1. decide what information

    you want to store 2. decide what TYPE is that data ex: date, varchar, char, 3. create table 4. create table structure
  6. Table data TYPE Type 型態 空間需 求 範圍 TINYINT 1

    Signed: -128 to 127 Unsigned: 0 to 255 INT 4 Signed: -2147683648~2147683647 Unsigned: 0~4294967295 DATE 3 1000-01-01~9999-12-31
  7. File Structure mysqli.php Database 物件, 拿來與 mysqli 做連線,下指令 create.php update.php

    delete.php 接收使⽤用者指令,並使⽤用 db 物件操作資料庫 list.php item.php 顯⽰示畫⾯面 update.php
  8. Read from Database SELECT * FROM user 1. Make connection

    2. SELECT * from table_name 3. execute query 4. parse result( $result->num_rows) 5. Close connection
  9. Update from Database 1. We must have ID to determine

    which record to modified 2. We must know the what columns to update 3. Make connection 4. UPDATE table SET foo=bar …….. WHERE id=? 5. execute query 6. Close Connection