KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

Often used PHP Mysql functions

Before you start this lesson, please check if you have installed MySQL on your PC. If not, install your MySQL database server now.

The most often used database by PHP is MySQL. The following functions are most often used MySQL functions:

MySQL function
mysql_connect Open a connection to a MySQL Server
mysql_close Close MySQL connection
mysql_select_db Select a MySQL database
mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_row Get a result row as an enumerated array
mysql_num_rows Get number of rows in result
mysql_field_name Get the name of the specified field in a result
mysql_num_fields Get number of fields in result
mysql_query Send a MySQL query
mysql_result Get result data
mysql_free_result Free result memory

The above functions could be grouped into the following categories:

  1. deal with database connection (mysql_connect, mysql_select_db, mysql_close)
  2. Query database and get result (mysql_query)
  3. dealing with result(mysql_fetch_array, mysql_fetch_row, mysql_num_rows, mysql_num_fields,mysql_result,mysql_free_result)

These 3 categories are the basic functions any talking to database language should have.

The following example shows basic usage of the above functions. It could fit into your PHP file and with a little bit change.

// Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
//select which database you want to use
mysql_select_db('my_database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM my_table';
//get query result
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
//get query result into array $line
echo "<table>\n";
while ($line = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
echo "\t</tr>\n";
echo "</table>\n";
// Free resultset
//close databae connection nnection

Another way to get result set is using while loop and mysql_result function:

//how many rows in result;
//how many columns in result
//write result into html table;
echo "<table border=1>";
//mysql_field_name($result,$col) get field name
echo "<tr><td>$name</td></tr>";

PHP Calendar
Comprehensive PHP Web Calendar
Configurable PHP Calendar
PHP Calendar
PHP Image Processing
PHP grahic softwares
PHP create real-time dynamic chart
create antispam image(image verification)
Add water mark to image
PHP Image processing introduction
Add text on Image
Create thumbnail for image
Create image from text on fly
PHP code sample
PHP create dynamic PDF with FPDF
PHP create dynamic PDF with PDFLib
PHP create dynamic PDF with ClibPDF
Improved PHP configurable hit counter
Install phpMyAdmin,MySql, PHP
PhpMyAdmin export/import data
A simple PHP RSS feed reader
PHP include (SSI)
Working with Forms
PHP formmail Generator
Using phpMyAdmin Create Database
Insert Form Data into Database
Retrieve data from Database
Retrieve multiple records
Batch insert text using phpMyAdmin
Using phpMyAdmin insert binary file
Insert binary file using PHP code
Using form insert binary file into MySQL
Retrieve binary file from MySQL
Image hosting business in minutes
Send HTML mail in PHP
Send bulk emails in PHP
Polling/Rating System in PHP
Polling/Rating System in PHP(radio button)
Check visitor's IP address
Check reciprocal link
PHP tutorial
What is PHP?
Install PHP on Windows XP (part1)
Install PHP on Windows XP (part2)
PHP open and closing tags
PHP types
Logic Structures
Include files
Set cookie and delete cookie
Most often used MySQL functions




Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © All rights reserved(new). Privacy|Copyright
designed by

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer