Download presentation
Presentation is loading. Please wait.
1
Website Development Working with MySQL
2
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
3
: Customer browser request service access page interpret set data present html return html get data databasescripting language web server Reminder of the general process today’s emphasis
4
Essential PHP functions http://www.php.net/manual/en/ref.mysql.php
5
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.
6
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.
7
MyDBFunctions.php
8
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.
9
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.
10
Now some SQL
11
CREATE TABLE ( col_name col_type,... ) http://www.mysql.com/doc/C/R/CREATE_TABLE.html
12
CREATE TABLE DATEPERSON ( NAME TEXT, AGE INT, HOBBIES TEXT, EMAIL TEXT, LIKES TEXT, HATES TEXT, POSTCODE TEXT, LOWERAGE INT, UPPERAGE INT )
13
test
14
DROP TABLE DATEPERSON DROP TABLE http://www.mysql.com/doc/D/R/DROP_TABLE.html
15
test
16
INSERT INTO SET Col_name = value,... http://www.mysql.com/doc/I/N/INSERT.html
17
INSERT INTO DATEPERSON SET NAME = “ROMEO", AGE = 14, HOBBIES = "maudling", EMAIL = "romeo@montague.com", LIKES = "Mercutio", HATES = "Tibbalt", POSTCODE = "VE21 2BB", LOWERAGE = 14, UPPERAGE = 16
18
test
19
SELECT FROM WHERE,,... http://www.mysql.com/doc/S/E/SELECT.html
20
SELECT * FROM DATEPERSON
21
test
22
Have a look at this Sample Database Application
23
What else? Forms for input – JavaScript validation? Forms for editing existing data Better error trapping An attractive interface – style sheets etc.
24
So what have we got now? Full database access Internet presentation In principle, most business applications can be served in this way
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.