Monthly Archives: November 2011

PHP-MySQL Lesson: DELETE statement

DELETE statement

In this lesson we are going to write a PHP script that deletes records in MySQL database using the DELETE statement.

We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.

In this lesson we need to three pages namely the list.php, deleteform.php and deleteprocess.phpHere is the code(list.php):

PHP-MySQL Lesson: UPDATE statement

UPDATE statement

In this lesson we are going to write a PHP script that updates records in MySQL database using the UPDATE statement.

Parameter of UPDATE command:

  • UPDATE – Performs an update MySQL query
  • SET – Updates (assigns new value to) columns in the selected table rows.
  • WHERE – Limits which rows are affected

We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.

PHP-MySQL Lesson: The ORDER BY Clause

The ORDER BY Clause

In this lesson we are going to write PHP scripts that select a records in MySQL and sort it using the ORDER BY clause.

Using ORDER BY clause we can sort the data in a recordset in a ascending or descending order.

ASC – ascending order (default)
DESC – descending order

We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.Here is the code:

PHP-MySQL Lesson: The Where Clause

The Where Clause

In this lesson we are going to write PHP scripts that select a specific records in MySQL using the WHERE clause

Using WHERE clause we can specify a selection criteria to select, update,delete required records from a table.

We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.Here is the code: name it as php_where.php

PHP-MySQL Lesson: Select Data in Database and Display the record in HTML table

PHP-MySQL Lesson: Select Data in Database and Display the record in HTML table

In this lesson we are going to write PHP scripts that select records in MySQL database and display it in HTML table.

The SELECT statement in sql is used to select a record in the database. In PHP, mysql_query() function is used to execute SELECT query.Here is the code: save it as php_select.php

PHP-MySQL Lesson: Insert records

Insert records

In this lesson we are going to write a PHP script that inserts a new record in our database through HTML forms.

The INSERT INTO statement in sql is used to insert a record in the database. In PHP, mysql_query() function is used to execute INSERT INTO query. We can execute any sql query like insert, update, delete, select etc. using the mysql_query() function.

We need two pages here namely the insert.php and the insertform.php or insertform.html.On our insertform.html we are going to create a form to collect the data entered by the user.

MySQL Tutorial – Using Column Aliases

Column Aliases

To rename a column in database table, use the AS keyword it allows you to alias the name to different value.

The syntax of AS keyword:

SELECT column_name(s)AS alias_name FROM table_name

AS keyword example:

SELECT f_name AS Firstname FROM employee_record;

PHP-MySQL Lesson: Select Database

Select Database

After we have establish the connection in MySQL server, we have to select a database. To do that we are going to use the mysql_select_db() function.

Syntax:

mysql_select_db(databasename,connection)

Parameter:

databasename – the database name you want to use.

connection – Specifies the MySQL connection

PHP-MySQL Lesson – Create Table

Creating a  Table

In this lesson we are going to write a PHP script that will create a table in our MySQL database.

To create a table in MySQL, use the command CREATE TABLE tablename. In PHP,mysql_query() function is used to execute CREATE TABLE command and other SQL query.

Here is an example script:

PHP-MySQL Lesson – Create Database

Creating a Database

The CREATE DATABASE statement in sql is used to create a database in MySQL. In PHP,mysql_query() function is used to execute sql query like insert, delete, update, select etc.

Here is an example PHP script that creates a database in MySQL: save it asphp_createDB.php