Thursday 23 August 2012

PHP/Mysql Follow up !

PHP/Mysql Follow up !

In previous tutorials, we have discussed in details how to connect to mysql server and how to execute sql queries.We are going to just go-through again  about database connectivity in php
  • We will connect to database server with mysql_connect()
  • We will select database name with mysql_select_db()
  • We will execute sql command using mysql_query()
That’s all you need to process database connectivity.


Suppose, you want to select all records from a table in a database. Then you will execute a sql select command
$query=Select * from table name;
And you will call mysql_query($query);
This will return an array of all records in table.

 The most important type of operation in an online website is storing and retrieving data in a database. And you need only three php functions to handle this operation.

Other important database related php functions are
  1. Mysql_num_rows() // return number of record returned by sql command
  2. Mysql_insert_id() // this function will return the id of the last row
  3. Mysql_affected_rows() // will return number of rows affected during update
  4. Mysql_fetch_array() // this will fetch results from associated arrays

No comments:

Post a Comment