Creating a Connection between PHP and Mysql
To update,create,change,insert .. a database you need to create a connection between mysql and php.
To connect with a database we can use the function mysql_connect()
Function mysql_connect() need 3 main parameters they are server name user name and password.
Code to Connect with a database
<?php
$server="localhost"; // SERVER NAME Default is localhost
$user = "root"; // USER NAME Default is root
$pass = ""; // PASSWORD Default is nothing
$connection = mysql_connect($server,$user,$pass);
if (!$connection)
{
echo "An error occurred";
}
mysql_query("") // INSERT YOUR SQL QUERY BETWEEN ""
mysql_close($connection);
?>
To update,create,change,insert .. a database you need to create a connection between mysql and php.
To connect with a database we can use the function mysql_connect()
Function mysql_connect() need 3 main parameters they are server name user name and password.
Code to Connect with a database
<?php
$server="localhost"; // SERVER NAME Default is localhost
$user = "root"; // USER NAME Default is root
$pass = ""; // PASSWORD Default is nothing
$connection = mysql_connect($server,$user,$pass);
if (!$connection)
{
echo "An error occurred";
}
mysql_query("") // INSERT YOUR SQL QUERY BETWEEN ""
mysql_close($connection);
?>
No comments:
Post a Comment