Variables in PHP
To storing the values we are using variables, like text strings, numbers and arrays. We can use variable in whole programme. The variables start with $ sign.
Example
$var_name = value;
Rules for variable
- A variable name must start with a letter or an underscore "_"
- A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
- A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)
MySQL Database
MySQL is database. MySQL is stored in database objects called tables. A table is a collection of related data entries and it consists of columns and rows.
MySQL Connection
In PHP, my connection function is:
mysql_connect(servername,username,password);
Example of MySQL connection in PHP
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
Closing Connection
The connection will be closed automatically when the script ends.
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>
Reference
n.d (2010). PHP. Retrieved on 23/05/2010 from http://www.w3schools.com/php/default.asp

As I know the basic information about PHP. Now I can write simple programme in PHP as you mention here about variables and their rules. Even I can connect my small database (SQL) with my programme. That’s grate!!!! Really well organize blog Vaibhavi!!!!
ReplyDelete