PHP-language, database-programming Jouni Juntunen Oulu University of Applied Sciences School of Business and Management Studies
Idea of database programming End users do not use database from management console using SQL-statements Create UI (web-page, windows form, etc.) for end user and permorm database manipulation in application code (e. g. in PHP-script)
Database-programming API (Application programming interface) Database-driver
Basic steps of database programming Open connection to database-server and Select database Manipulate data Close connection
Example: Read data from database
mysql_fetch_row Structure of the table in database Data (records) of the table in database mysql_fetch_row read one record at time and the return value is array containing information of all fields
Example: Insert data into database newMessage.html save.php
Opening connection Connection to database server must be opened before manipulating data Check always for error when opening database connections
Select database to use Select database to use Servers may have several different databases
Manipulate data Reading information Inserting, updating and deleting mysql_query containing select sql-statement mysql_fetch_row inside while loop Inserting, updating and deleting mysql_query containing sql-statement that manipulates data
Close connection Connection to database (server) must be always closed after manipulatin data Open connections consumes resources from server