website development working with mysql. what you will achieve today! connecting to mysql creating...

24
Website Development Working with MySQL

Post on 22-Dec-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

Website Development

Working with MySQL

Page 2: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

What you will achieve today!

•Connecting to mySql•Creating tables in mySql•Saving data on a server using mySql•Getting data from the server using mySql

Page 3: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

: Customer browser

request service

access page

interpretset data

present html

return html

get data

get data

databasescripting language

web server

Reminder of the general process

today’semphasis

Page 4: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

Essential PHP functions

http://www.php.net/manual/en/ref.mysql.php

Page 5: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

mysql_connect ([string hostname, string username [, string password]]])

Returns a positive MySQL link identifier on success, or an error message on failure.

mysql_connect() establishes a connection to a MySQL server.

Page 6: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

mysql_query (string query [, int link_identifier])

mysql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed.

mysql_query() returns TRUE (non-zero) or FALSE to indicate whether or not the query succeeded. A return value of TRUE means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly possible for a query to succeed but affect no rows or return no rows.

Page 7: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

MyDBFunctions.php

Page 8: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

array mysql_fetch_row (int result)

Returns: An array that corresponds to the fetched row, or false if there are no more rows.

mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Subsequent call to mysql_fetch_row() would return the next row in the result set, or false if there are no more rows.

Page 9: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

mysql_num_rows (int result)

mysql_num_rows() returns the number of rows in a result set. This command is only valid for SELECT statements.

mysql_num_fields (int result)

mysql_num_fields() returns the number of fields in a result set.

Page 10: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

Now some SQL

Page 11: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

CREATE TABLE <tablename> (col_name col_type,col_name col_type,...

)

http://www.mysql.com/doc/C/R/CREATE_TABLE.html

Page 12: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

CREATE TABLE DATEPERSON (NAME TEXT,AGE INT,HOBBIES TEXT,EMAIL TEXT,LIKES TEXT,HATES TEXT,POSTCODE TEXT,LOWERAGE INT,UPPERAGE INT

)

Page 14: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

DROP TABLE DATEPERSON

DROP TABLE <tablename>

http://www.mysql.com/doc/D/R/DROP_TABLE.html

Page 15: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

test

Page 16: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

INSERT INTO <tablename> SETCol_name = value,Col_name = value,...

http://www.mysql.com/doc/I/N/INSERT.html

Page 17: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

INSERT INTO DATEPERSON SETNAME = “ROMEO",AGE = 14,HOBBIES = "maudling",EMAIL = "[email protected]",LIKES = "Mercutio",HATES = "Tibbalt",POSTCODE = "VE21 2BB",LOWERAGE = 14,UPPERAGE = 16

Page 18: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

test

Page 19: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

SELECT <column names>FROM <tablename>WHERE <col_name comparison value>,

<col_name comparison value>,...

http://www.mysql.com/doc/S/E/SELECT.html

Page 20: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

SELECT * FROM DATEPERSON

Page 21: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

test

Page 22: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

Have a look at this

Sample Database Application

Page 23: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

What else?

• Forms for input – JavaScript validation?

• Forms for editing existing data

• Better error trapping

• An attractive interface – style sheets etc.

Page 24: Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql

So what have we got now?

Full database accessInternet presentationIn principle, most business applications can be served in this way