Date post: | 15-Jul-2015 |
Category: |
Software |
Upload: | mohammad-tahsin-al-shalabi |
View: | 248 times |
Download: | 1 times |
FilesExample
INPUT :
Price and product changes
OUTPUT :
Catalogue
Catalogue
File
Record Format :
(Product_no, Description, Price)
$file=fopen("welcome.txt","r");
fclose($file)
feof($file)
fgets($file) fgetc($file)
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
What is Database?
A database is an organized collection of data. The data are typically organized to model relevant aspects of reality in a way that supports processes requiring this information
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
Database Vs FilesFiles problems
• Have to write procedures to manage the accessibility of common files.
• Errors occurs through using the files.
• Editing common files structure require editing all the programs that deal with this file.
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
• What is MySQL?
MySQL is a database system used on the web
MySQL is a database system that runs on a server
MySQL is ideal for both small and large applications
MySQL is very fast, reliable, and easy to use
MySQLIntro
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
• What is MySQL?
MySQL supports standard SQL
MySQL compiles on a number of platforms
MySQL is free to download and use
MySQL is developed, distributed, and supported by Oracle Corporation
MySQLIntro
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
• Connect to DB:
mysql_connect('localhost',‘db_user',‘db_pass')
• Verifying and Select DB:
mysql_select_db(‘db_name')
MySQLConfiguration
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
• Why ?
To insert the content of one PHP file into another PHP file before the server executes it.
• Syntax:
Include & Require
include 'filename';
or
require 'filename';
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
• What is Query ?
A query is a question or a request.
We can query a database for specific information and have a record set returned.
• Ex:
SELECT LastName FROM Employees
MySQLQuery
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
• How can I write Query in php ?
$result = mysql_query("SELECT * FROM Persons");
• How can I get the results ?
mysql_fetch_array($result);
mysql_fetch_assoc($result);
MySQLQuery with php
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
MySQLCreate new DB
// Create database$sql="CREATE DATABASE my_db";if (mysql_query($sql)) {
echo "Database my_db created successfully";} else {
echo "Error creating database: " . mysqli_error($con);}
OR
MySQLCreate new Table
// Create table$sql="CREATE TABLE Persons(FirstName CHAR(30),LastNameCHAR(30),Age INT)";if (mysql_query($sql)) {
echo "Table persons created successfully";} else {
echo "Error creating table: " . mysqli_error($con);}
OR
MySQLInsert Date to a Table
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)VALUES ('Peter', 'Griffin',35)");
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)VALUES ('Glenn', 'Quagmire',33)");
OR
MySQLSelect Data from Table
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result)) {echo $row['FirstName'] . " " . $row['LastName'];echo "<br>";
}
MySQLWhere clause
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
$result = mysql_query("SELECT * FROM PersonsWHERE FirstName='Peter'");
while($row = mysql_fetch_array($result)) {echo $row['FirstName'] . " " . $row['LastName'];echo "<br>";
}
MySQLUpdate Data In a Database
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
mysql_query("UPDATE Persons SET Age=36WHERE FirstName='Peter' AND LastName='Griffin'");
MySQLDelete Data In a Database
By: Mohammad Al-Shalabi & Mohammad Opada Al-Bosh
mysql_query(“DELETE FROM PersonsWHERE FirstName='Peter' AND LastName='Griffin'");