To connection database on MySQL in this articel we using 3 method :
1.Create Data base
2.Create Table
3.Insert Record
4.Make File test_mysql.php
5.Running on web browser
Step-1.Create Database
Paste this coding into Window SQL in PHPMyAdmin window.
Create database test;
Step-2.Create table into database test.
Paste this Code into Sql Windows
CREATE TABLE `test`.`table_tes` (
`id` INT NOT NULL AUTO_INCREMENT ,
`first_name` VARCHAR( 25 ) NOT NULL ,
`last_name` VARCHAR( 25 ) NOT NULL ,
`email` VARCHAR( 25 ) NOT NULL ,
`city` VARCHAR( 25 ) NOT NULL ,
PRIMARY KEY ( `id` )
`first_name` VARCHAR( 25 ) NOT NULL ,
`last_name` VARCHAR( 25 ) NOT NULL ,
`email` VARCHAR( 25 ) NOT NULL ,
`city` VARCHAR( 25 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM
Step-3.Insert record into table table_tes
Paste this code into SQL window make sure database test is choise.
INSERT INTO `test`.`table_tes` (`id` ,`first_name` ,`last_name` ,`email` ,`city`)
VALUES (NULL , 'Adam', 'Moh', 'adam@aol.com', 'Lhokseumawe');
VALUES (NULL , 'Adam', 'Moh', 'adam@aol.com', 'Lhokseumawe');
Step-4.Make File test_mysql.php
Make File and save with name test_mysql.php save on htdocs
Paste this code into file test.php and running on the web browser with address name http://localhost/tes_mysql.php
View in Dreamweaver
Paste this under code into your Window application web design :
$host="localhost";
$user="root";
$pass="";
$db="test";
$tbl_name="table_tes";
$connect=mysql_connect($host,$user,$pass)or die(mysql_error());
$select_db=mysql_select_db($db,$connect);
if ($connect) {
print "Success Connected to Database test";
} else {
print "Error connection";
}
?>
$query="SELECT * FROM $tbl_name";
$result=mysql_query($query);
?>
while ($row=mysql_fetch_array($result)) {
?>
}
?>
| ID | First Name | Last Name | City | |
Step-5. Running on localhost typing addres http://localhost/tes_mysql.php on your web browser.