Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
here is a simple connection between php and mysql. in5 steps .
Step1: create the db
CREATE DATABASE `mydb`;USE `mydb`;CREATE TABLE `employee` ( `id` int UNIQUE NOT NULL AUTO_INCREMENT, `first_name` varchar(40), `last_name` varchar(50), PRIMARY KEY(id));INSERT INTO cars VALUES('usama','saad');INSERT INTO cars VALUES('hasan','hamaky');INSERT INTO cars VALUES('noor','sobhy');
Step2: Get Connection with the db
$username = "your_name";$password = "your_password";$hostname = "localhost"; //connection to the database$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");echo "Connected to MySQL ";?>
Step3 Get your target schema
//select a database to work with$selected = mysql_select_db("mydb",$dbhandle) or die("Could not select mydb");?>
Step4: Start your interaction with the db:
//execute the SQL query and return records$result = mysql_query("SELECT id, first_name, last_name FROM employee");//fetch tha data from the databasewhile ($row = mysql_fetch_array($result)) { echo "ID:".$row{'id'}." Name:".$row{'first_name'}." ".$row{'last_name'}." "; }?>
Step5: Close the connection: //close the connectionmysql_close($dbhandle);?>
refrence :
http://usama-saad.blogspot.com/2013/08/how-to-start-php-mysql-connection.html
Simple! You can make a connection to your MySQL database from PHP using the mysql_connect() function. Here is its example:
<?php
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ;
mysql_select_db("Database_Name") or die(mysql_error()) ;
?>
The first variable (shown as your.hostaddress.com) is the location of your database. Often this is "localhost". The next two variables are your username and password. This is the login you use for your MySQL database.
In the second line, we choose which database you are connecting too. This is needed because the same MySQL username can be linked to several databases.
Cheers!
You may read here about it http://pk1.php.net/function.mysql-connect
I recommended using MYSQLI extention because mysql is Deprecated in php5 $_link_ = mysqli_connect( host , user , pass , database name ) or die( 'Mysql Error;'.mysqli_error()) ;
<?php
mysql_connect("hostName","dbUserName","dbPassword");
?>
step:1
To connect Database using this command
<?php
$connect=mysql_connect("localhost","root","") or die("Not connect to server");
$select=mysql_select_db("db_name",$connect) or die("Not connect with your DB");
?>
Hi
1- you should have the mysql module a .dll in windows and .so in linux (look in module directory)
2- it should be enabled in php.ini file
3-call function mysql_connect
it is very simple create php variable
step-1
$link = mysql_connect("localhost","root","123456") or die('Faile to login');
1. localhost is your local web server
2. root or any user you have created is your username with permited previlage
3 "123456" password given by the mysql user
step-2
mysql_select_db("pml",$link) or die("not connected")