Database Concepts CPTE 212 3/19/2015 John Beckett
Why use a database? Self-documenting Self-organizing Extensible –More data per ? –More transactions per hour
How to access a database < Write a program to read and write files DBMS included a DBML Database Management Language Standard DBML - > SQL
Database Access – 3-Tier Model Application Server (Apache or IIS) HTTP GET or POST HTTP Response JavaScript Server-Side Language Interpreter Content Database Server (e.g. MySQL) The database server may be physically housed on the Web server. We’ll be focusing on the relationship between Apache/PHP and the database server
Web App Server Database Server (MySQL) HW Server (Linux) SQL (Strings) Results (Objects) DB Protocol Note: the database server is in the same physical server as Apache and PHP for this class. There is no reason you can’t separate these functions on different computers. In a volume production environment, this is very likely. We’ll talk here as if the two functions were separated.
Oh, the Layers We Go Through… PHP has multiple language extensions that connect with the DB access protocol, which may be: –Some are unique to that database E.g. PHP’s mysql or mysqli API’s –A protocol supported by many databases (perhaps through a translation program) E.g. PHP’s ODBC API talking to the database server’s ODBC adapter SQL is carried over that protocol –Dialects of SQL vary somewhat between database engines –Some database engines have features others don’t have
Programming for the Web Connect to the database server –Username / password –…implies privileges –Yields a connection object Select a database Send SQL –Receive results from it Close the connection For all of these, there is a possibility of error result
Yet Another Language!!!! You’ll learn SQL in CPTR 319 For now: –Use phpmyadmin’s query function to generate sample SQL –Copy the SQL into your PHP program –Use PHP to edit the SQL so that it actually works for the specific case in question