Senin, 10 September 2012

0 Database ; PHP & MYSQL

MEMUNCULKAN DATABASE MYSQL DALAM BENTUK TABLE MENGGUNAKAN PHP..


<?php
include "config.php";
$no = 1;
$sql = "SELECT * from stasiun";
$hasil = mysql_query($sql) or die (mysql_error());
$cekdata = mysql_num_rows($hasil);
if ($hasil==0) {
    echo "data tidak ada";
    }
    else {
    echo "<table border='1' cellspacing=0 cellpadding=0 width=80%>
<tr>
<th scope=col> <abbr=No class=nobg>No</th>
<th scope=col> NAMA_STASIUN RADIO </th>
<th scope=col> ALAMAT </th>
<th scope=col> FREKUENSI</th>
</tr>";

while ($stasiun = mysql_fetch_array($hasil))
    {
    echo "<tr>";
    echo "<td scope=row class=spec align=center>".$no++."</td>";
    echo "<td>" . $stasiun['Nama'] . "</td>";
    echo "<td>" . $stasiun['Alamat'] . "</td>";
    echo "<td>" . $stasiun['Frekuensi'] . "</td>";
    echo "</tr>";
    }
echo "</table>";

}
mysql_close();
?>

0 Tugas Alter table; Radio

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\pcs31>cd\xampp\mysql\bin

C:\xampp\mysql\bin>dor/
'dor' is not recognized as an internal or external command,
operable program or batch file.

C:\xampp\mysql\bin>dir/
Invalid switch - "".

C:\xampp\mysql\bin>dir/w
 Volume in drive C has no label.
 Volume Serial Number is 3837-CD8F

 Directory of C:\xampp\mysql\bin

[.]                     [..]                    bug25714.exe
comp_err.exe            echo.exe                libmysql.dll
my.ini                  myisamchk.exe           myisamlog.exe
myisampack.exe          myisam_ftdump.exe       mysql.exe
mysqladmin.exe          mysqlbinlog.exe         mysqlcheck.exe
mysqld.exe              mysqldump.exe           mysqlimport.exe
mysqlmanager.exe        mysqlshow.exe           mysqlslap.exe
mysqltest.exe           mysql_client_test.exe   mysql_config.bat
mysql_config.pl         mysql_upgrade.exe       my_print_defaults.exe
perror.exe              replace.exe             resolveip.exe
              28 File(s)     42.888.587 bytes
               2 Dir(s)  55.463.063.552 bytes free

C:\xampp\mysql\bin>mysql -h localhots -u root
ERROR 2005 (HY000): Unknown MySQL server host 'localhots' (11004)

C:\xampp\mysql\bin>mysql -h localhost -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.1.41 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> delete database radio;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'datab
ase radio' at line 1
mysql> drop database radio;
Query OK, 4 rows affected (0.07 sec)

mysql> create database radio;\
Query OK, 1 row affected (0.00 sec)

mysql> use radio;
Database changed
mysql> create table stasiun (id_radio int(4) primary key not null auto_increment

    -> , nama varchar(100),alamat text, frekuensi varchar(100))engine=innodb;
Query OK, 0 rows affected (0.03 sec)

mysql> create table program (id_program int(5) primary key not null auto_increme

    -> nt, id_radio int(4) not null, nama_program varchar(50), onair_day text, o
nair_ho
    -> ur text)engine=innodb;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'auto_
increme
nt, id_radio int(4) not null, nama_program varchar(50), onair_day t' at line 1
mysql> create table program (id_program int(5) primary key not null auto_increme

    -> nt, id_radio int(4) not null, nama_program varchar(50), onair_day text, o
nair_ho
    -> ur text)engine=innodb;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'auto_
increme
nt, id_radio int(4) not null, nama_program varchar(50), onair_day t' at line 1
mysql> create table program (id_program int(5) primary key not null auto_increme
nt, id_radio int(4) not null, nama_program varchar(50), onair_day text, onair_ho
ur text)engine=innodb;
Query OK, 0 rows affected (0.03 sec)

mysql> create table detil_penyiar (id_penyiar int(5) primary key not null auto_i
ncrement, nama varchar(100), jenis_kelamin varchar(1), no_hp  varchar(16))engine
=innodb;
Query OK, 0 rows affected (0.06 sec)

mysql> create table penyiar (id int(5), id_penyiar int(5), id_program int(5))eng
ine=innodb;
Query OK, 0 rows affected (0.03 sec)

mysql> insert into stasiun values('1','bekasi center','cyber park b1/15','111.1'
);
Query OK, 1 row affected (0.02 sec)

mysql> insert into stasiun values('2','gen fm','bekasi utara a1/6','98.7');
Query OK, 1 row affected (0.02 sec)

mysql> desc program;
+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| id_program   | int(5)      | NO   | PRI | NULL    | auto_increment |
| id_radio     | int(4)      | NO   |     | NULL    |                |
| nama_program | varchar(50) | YES  |     | NULL    |                |
| onair_day    | text        | YES  |     | NULL    |                |
| onair_hour   | text        | YES  |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)

mysql> insert into program values('101','1','canda sutra','senin-jumat','01;00-0
3;00')
    -> ;
Query OK, 1 row affected (0.02 sec)

mysql> insert into program values('102','2','telat sekolah','selasa,kamis,jumat'
,'03;00-04;00);
    '> '
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> insert into program values('102','2','telat sekolah','selasa,kamis,jumat'
,'03;00-04;00');
Query OK, 1 row affected (0.02 sec)

mysql> desc ddetil_penyiar;
ERROR 1146 (42S02): Table 'radio.ddetil_penyiar' doesn't exist
mysql> desc detil_penyiar;
+---------------+--------------+------+-----+---------+----------------+
| Field         | Type         | Null | Key | Default | Extra          |
+---------------+--------------+------+-----+---------+----------------+
| id_penyiar    | int(5)       | NO   | PRI | NULL    | auto_increment |
| nama          | varchar(100) | YES  |     | NULL    |                |
| jenis_kelamin | varchar(1)   | YES  |     | NULL    |                |
| no_hp         | varchar(16)  | YES  |     | NULL    |                |
+---------------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> insert into detil_penyiar values('201','sucaksono','L','0878885695');
Query OK, 1 row affected (0.02 sec)

mysql> insert into detil_penyiar values('202','wagibin','L','081343676895');
Query OK, 1 row affected (0.02 sec)

mysql> desc penyiar;
+------------+--------+------+-----+---------+-------+
| Field      | Type   | Null | Key | Default | Extra |
+------------+--------+------+-----+---------+-------+
| id         | int(5) | YES  |     | NULL    |       |
| id_penyiar | int(5) | YES  |     | NULL    |       |
| id_program | int(5) | YES  |     | NULL    |       |
+------------+--------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> insert into penyiar values('1','201','101')
    -> ;
Query OK, 1 row affected (0.01 sec)

mysql> insert into penyiar values('2','202','102')
    -> ;
Query OK, 1 row affected (0.02 sec)

mysql> alter table program add constraint foreign key (id_radio) references stas
iun (id_radio) on delete cascade on update cascade;
Query OK, 2 rows affected (0.06 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> alter table penyiar add constraint FK_mykey foreign key (id_program) refe
rences program (id_program) on delete cascade on update cascade;
Query OK, 2 rows affected (0.09 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> alter table detil_penyiar add constraint FK_mykey1 foreign key (id_penyia
r) references penyiar (id_penyiar)on delete cascade on update cascade;
ERROR 1005 (HY000): Can't create table 'radio.#sql-668_1f' (errno: 150)
mysql> alter table penyiar (id_penyiar) add constraint FK_mykey1 foreign key (id
_penyiar) references detil_penyiar (id_penyiar)on delete cascade on update casca
de;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '(id_p
enyiar) add constraint FK_mykey1 foreign key (id_penyiar) references detil_' at
line 1
mysql> alter table penyiar add constraint FK_mykey1 foreign key (id_penyiar) ref
erences detil_penyiar (id_penyiar)on delete cascade on update cascade;
Query OK, 2 rows affected (0.07 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select*from stasiun
    -> ;
+----------+---------------+-------------------+-----------+
| id_radio | nama          | alamat            | frekuensi |
+----------+---------------+-------------------+-----------+
|        1 | bekasi center | cyber park b1/15  | 111.1     |
|        2 | gen fm        | bekasi utara a1/6 | 98.7      |
+----------+---------------+-------------------+-----------+
2 rows in set (0.00 sec)

mysql> select * from program;
+------------+----------+---------------+--------------------+-------------+
| id_program | id_radio | nama_program  | onair_day          | onair_hour  |
+------------+----------+---------------+--------------------+-------------+
|        101 |        1 | canda sutra   | senin-jumat        | 01;00-03;00 |
|        102 |        2 | telat sekolah | selasa,kamis,jumat | 03;00-04;00 |
+------------+----------+---------------+--------------------+-------------+
2 rows in set (0.00 sec)

mysql> select * from detil_penyiar;
+------------+-----------+---------------+--------------+
| id_penyiar | nama      | jenis_kelamin | no_hp        |
+------------+-----------+---------------+--------------+
|        201 | sucaksono | L             | 0878885695   |
|        202 | wagibin   | L             | 081343676895 |
+------------+-----------+---------------+--------------+
2 rows in set (0.00 sec)

mysql> select* from penyiar;
+------+------------+------------+
| id   | id_penyiar | id_program |
+------+------------+------------+
|    1 |        201 |        101 |
|    2 |        202 |        102 |
+------+------------+------------+
2 rows in set (0.00 sec)

mysql>
 

My Lesson Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates