MySQL
is one of the databases, a place to put the data in a structured form of tables
and we can do a query or process the data with SQL (Structured Query Language).
Tools that can be used one of them is phpmyadmin, with this tool, we do not
have to hafalm with SQL select command, create, update.
Here
I will explain how to create web pages using PHP and MySQL.
The
first step is to connect to the database. And make sure that our local server
is already active.
<?php
$koneksi = mysql_connect("localhost","root","");
if($koneksi){
echo "Koneksi berhasil";
}else{
echo "Gagal";
}
?>
The next step is to create a database. There are 2 ways that can be used, the first one is using phpmyadmin
Once filled with
the name of the database, click Create. Next is to create a table.
Enter the name
of the table you want, then enter the number of columns, and click Go. Then the
display appears as below
Note:
null
means that at the time of filling the database, bukuid field can not be empty.
Index
to define as the primary key or other
A_I short for auto increment, Auto Increment function to generate a unique
number when a new data entered. This will happen automatically every the
addition of new data
In
addition, we can also create a database using PHP, the following syntax
<?php
//lakukan koneksi ke MySQL
mysql_connect("localhost","root","");
//pilih database tempat tabel akan dibuat
mysql_select_db("nama_database");
$query = "CREATE TABLE nama_tabel(
bukuid int(5)
auto_increment primary key,
judul varchar(50),
tahun year,
pengarang varchar
(50),
penerbit varchar (30)
)";
//jalankan query
$buat = mysql_query($query);
if($buat){
echo "Tabel nama_tabel
berhasil dibuat";
}else{
echo
"Gagal";
}
?>
Good
Luck!
0 komentar:
Posting Komentar