Archive

Archive for the ‘MySql’ Category

MySQL PHP Connection

July 28th, 2010 admin No comments

Before you can do anything with MySQL in PHP you must first establish a connection to your web host’s MySQL database. This is done with the MySQL connect function.

Syantax

mysql_connect(servername,username,password);

Example

mysql_connect(“localhost”,”guest”,”abc123″);

Example with PHP

In the following example we store the connection in a variable ($connection) for later use in the script. The “die” part will be executed if the connection fails:

<html>
<head>
<title>Connecting MySQL Server</title>
</head>
<body>
<?php
$dbhost = ‘localhost’;
$dbuser = ‘guest’;
$dbpass = ‘abc123′;
$connection = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $connection)
{
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully’;
mysql_close($connection);
?>
</body>
</html>

You can disconnect from MySQL database anytime using another PHP function mysql_close().

Categories: MySql Tags:

MySQL Tutorial with PHP Examples

July 28th, 2010 admin No comments

MySQL is the open-source database system.

Database: A database is a collection of tables, with related data.

Table: A table is a collections of related data entries and it consists of columns and rows.

Databases are useful when storing information categorically. A college may have a database with the following tables: “Employees”, “Students” and “Departments”.

MySQL PHP Syntax

MySQL works very well in combination of various programming languages like PERL,JAVA and PHP. Out of these languages, PHP is the most popular one because of its web application development capabilities.

This tutorial focuses heavily on using MySQL in a PHP environment. PHP provides various functions to access MySQL database and to manipulate data records inside MySQL database.

The PHP functions for use with MySQL have the following general format:

mysql_function(arg 01,arg 02,…);

Categories: MySql Tags: