The document discusses classes and objects in PHP and provides examples of creating a basic class with properties and methods. It also discusses connecting to a MySQL database, creating tables, inserting, selecting, updating and deleting data from MySQL tables using PHP.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
11 views3 pages
Reviewer Web Desginprefinals
The document discusses classes and objects in PHP and provides examples of creating a basic class with properties and methods. It also discusses connecting to a MySQL database, creating tables, inserting, selecting, updating and deleting data from MySQL tables using PHP.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
Classes and Objects Each instance/object creates has the
same properties and methods but can
• Class - is a template for objects. have different values. • Object – an instance of class.
Basic class definitions begin with the class
keyword, followed by a class name and a pair of curly braces.
The class name can be any valid label,
provided it is not a PHP reserved word.
A valid class name starts with a letter or
underscore, followed by any number of letters, numbers or underscores. • Form – represents a document section • Properties – the constants/variables of containing interactive controls for a class. collecting user input. • Methods – the functions of a class. • To create a form, you use the <form> element with the action and method attributes. <?php
class SimpleClass {
// property declaration • Action – specifies the URL that
processes the form submission. public $name; • Method – specifies the HTTP method for // method declaration submitting the form.
function set_name($name) {
$this->name = $name;
function get_name () {
return $this->name;
?>
• $this – refers to the current object and
only available inside methods. • New - creates an instance of a class. • MySQL – is a database system used on • PHP uses the mysql_query function the web. to create a MySQL database. • It runs on a server and is ideal for • This function takes two parameters both small and large application. and returns TRUE on success or • is used for a wide range of purposes, FALSE on failure. including data warehousing, e- commerce, and logging applications.
• MYSQL Connection – a connection is like
a pipeline of sorts that allows communication between a DBMS and an application program. • we have to supply the following information when making a database connection: the host or URL of the database server, the • Create Table - A database table has database name, and the database its unique name and consists of user name and password. columns and rows. - CREATE TABLE statement is • Opening Database Connection - In PHP used to create a table in you can easily do this using the MySQL. mysqli_connect () function. All - To create tables in the new communication between PHP and the database, you need to do MySQL database server takes place the same thing as creating through this connection. the database. • NOT NULL – Each row must contain a value for that column; null values are not allowed. • DEFAULT VALUE - Set a default value that is added when no other value is passed. • UNSIGNED - Used for number types, limits the stored data to positive numbers and zero. • AUTO INCREMENT- MySQL • Closing Database Connection - The automatically increases the value of connection will be closed automatically the field by 1 each time a new when the script ends. To close the record is added. connection before. • PRIMARY KEY - Used to uniquely • Create Database - E statement is used to identify the rows in a table. The create a database in MySQL. To create column with the PRIMARY KEY and delete a database, you should have setting is often an ID number and is admin privilege. often used with AUTO_INCREMENT. • Select Data from a MySQL Database – The SELECT statement is used to select data from one or more tables. • fetch_assoc() - puts all the results into an associative array that we can loop through. • while() - loop loops through the result set and outputs the data from the id, firstname, and lastname columns. • Insert Data into MySQL - After a database and a table have been created, you can start adding data to them. - Here are some syntax rules to follow: ▪ The SQL query must be quoted in PHP ▪ String values inside the SQL query must be quoted ▪ Numeric values must not be quoted ▪ The word NULL must not be quoted
• Delete Data from a MySQL Table - The
DELETE statement is used to delete records from a table.
• Update Data in a MySQL Table - The
UPDATE statement is used to update existing records in a table.