Terminology Data Types SQL Queries PHPMySQL Examples
Terminology Data Types SQL Queries PHPMySQL Examples
Terminology
Data Types
SQL queries
PHP/MySQL
Examples
Relational Databases
● Formal (mathematical) basis
● Stores "relationships" by storing common
values in more than one table.
● Not the only kind of database
– object databases
– hierarchical
– network
rows (records)
Local
Application
SQL
Database
Remote SQL
Server
Application
(process)
Descending
Ascending
Database Intro (MySQL/PHP) 25
Shopping Cart
● Suppose we want to store a user's shopping
cart in the database.
– we need some way to store this information.
– we need to be careful how we set this up, doing it
the wrong way will make the system difficult to
maintain.
● Requirements:
– need to store information on the number of each
product in each users shopping cart.
--or--
SELECT *
FROM cartentries JOIN products ON
( cartentries.productid =
products.productid )
if (mysql_select_db("dbintro")) {
echo "<h3>Connected !</h3>\n";
} else {
echo "Error connecting: " . mysql_error();
exit;
}
mysql_query(SQLstring)
Example:
$res = mysql_query($q);
$num = mysql_num_rows($res);
echo "<p>I found $num records</p>";