Interfacing with MySQL Using PHP - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Interfacing with MySQL Using PHP

Description:

Interfacing with MySQL Using PHP. Creating Your First Database. For our subsequent examples ... Interfacing with MySQL Using PHP. mysql_connect('localhost' ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 10
Provided by: purdueuniv
Category:

less

Transcript and Presenter's Notes

Title: Interfacing with MySQL Using PHP


1
Interfacing with MySQL Using PHP
  • .

2
Creating Your First Database
  • For our subsequent examples
  • Server - localhost
  • Database test1
  • Table example1
  • Username - good
  • Password good1

3
Interfacing with MySQL Using PHP
  • mysql_connect("localhost", "good", "good1") or
    die(mysql_error())
  • mysql_select_db("test1") or die(mysql_error())

4
Interfacing with MySQL Using PHP
  • // Create a MySQL table in the selected database
  • mysql_query("CREATE TABLE example1(
  • id INT NOT NULL AUTO_INCREMENT,
  • PRIMARY KEY(id),
  • name VARCHAR(30),
  • age INT,
  • weight float)")
  • or die(mysql_error())

5
Interfacing with MySQL Using PHP
  • // Insert a row of information into the table
    "example"
  • mysql_query("INSERT INTO example1
  • (name, age, weight) VALUES('George Down', '23',
    '150.45' ) ")
  • or die(mysql_error())

6
Interfacing with MySQL Using PHP
  • // Retrieve all the data from the "example1"
    table
  • result mysql_query("SELECT FROM example1")
  • or die(mysql_error())
  • // store the record of the "example" table into
    row
  • row mysql_fetch_array( result )
  • // Print out the contents of the entry
  • echo "Name ".row'name'
  • echo " Age ".row'age'
  • echo " Weight ".row'weight'

7
Interfacing with MySQL Using PHP
  • // Retrieve all the data from the "example1"
    table
  • result mysql_query("SELECT FROM example1")
  • or die(mysql_error())
  • // store the record of the "example" table into
    row
  • row mysql_fetch_array( result )
  • // Print out the contents of the entry
  • echo "Name ".row'name'
  • echo " Age ".row'age'
  • echo " Weight ".row'weight'

8
Interfacing with MySQL Using PHP
  • // Print out the contents of the entry
  • row mysql_fetch_array(result) or
    die(mysql_error())
  • echo row'name'. " - ". row'age'. " - ".
    row'weight'

9
Interfacing with MySQL Using PHP
  • // Make a MySQL Connection
  • query "SELECT FROM example1"
  • result mysql_query(query) or
    die(mysql_error())
  • //Using while loop to get each row of the table
  • while(row mysql_fetch_array(result))
  • echo row'name'. " - ". row'age'. " - ".
    row'weight'
  • echo "ltbr /gt"
Write a Comment
User Comments (0)
About PowerShow.com