Bab24 PHP Mysql Create

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Bab 24 Membuat Database dan Tabel

Membuat Database CREATE DATABASE database_name Program24-1.php <?php !on " m#s$%_!onne!t&'%o!a%host'('peter'('ab!12)'*+ ,- &. !on* / d,e&0Co1%d not !onne!t2 0 . m#s$%_error&**+ 3 ,- &m#s$%_$1er#&'CREATE DATABASE m#_db'( !on** / e!ho 'Database !reated'+ 3 e%se / e!ho 'Error !reat,ng database2 ' . m#s$%_error&*+ 3 m#s$%_!%ose& !on*+ ?4

Membuat Tabel CREATE TAB5E tab%e_name & !o%1mn_name1 data_t#pe( !o%1mn_name2 data_t#pe( !o%1mn_name) data_t#pe( ....... * Program24-2.php <?php !on " m#s$%_!onne!t&'%o!a%host'('peter'('ab!12)'*+ ,- &. !on* / d,e&0Co1%d not !onne!t2 0 . m#s$%_error&**+ 3 66 Create database ,- &m#s$%_$1er#&'CREATE DATABASE m#_db'( !on** / e!ho 'Database !reated'+ 3 e%se / e!ho 'Error !reat,ng database2 ' . m#s$%_error&*+ 3 66 Create tab%e ,n m#_db database m#s$%_se%e!t_db&'m#_db'( !on*+

s$% " 'CREATE TAB5E Person & 7,rst8ame 9ar!har&1:*( 5ast8ame 9ar!har&1:*( Age ,nt *'+ m#s$%_$1er#& s$%( !on*+ m#s$%_!%ose& !on*+ ?4 Tipe Data di MySQL Numeric Data Types ,nt&s,;e* sma%%,nt&s,;e* t,n#,nt&s,;e* med,1m,nt&s,;e* b,g,nt&s,;e* de!,ma%&s,;e(d* do1b%e&s,;e(d* -%oat&s,;e(d* Textual Data Types !har&s,;e* 9ar!har&s,;e* Description <o%d ,ntegers on%#. The ma=,m1m n1mber o- d,g,ts !an be spe!,-,ed ,n the s,;e parameter

<o%d n1mbers >,th -ra!t,ons. The ma=,m1m n1mber o- d,g,ts !an be spe!,-,ed ,n the s,;e parameter. The ma=,m1m n1mber od,g,ts to the r,ght o- the de!,ma% ,s spe!,-,ed ,n the d parameter Description <o%ds a -,=ed %ength str,ng &!an !onta,n %etters( n1mbers( and spe!,a% !hara!ters*. The -,=ed s,;e ,s spe!,-,ed ,n parenthes,s <o%ds a 9ar,ab%e %ength str,ng &!an !onta,n %etters( n1mbers( and spe!,a% !hara!ters*. The ma=,m1m s,;e ,s spe!,-,ed ,n parenthes,s <o%ds a 9ar,ab%e str,ng >,th a ma=,m1m %ength o- 2:: !hara!ters <o%ds a 9ar,ab%e str,ng >,th a ma=,m1m %ength o- ?::): !hara!ters <o%ds a 9ar,ab%e str,ng >,th a ma=,m1m %ength o- 1?@@@21: !hara!ters <o%ds a 9ar,ab%e str,ng >,th a ma=,m1m %ength o- 42A4A?@2A: !hara!ters

t,n#te=t te=t b%ob med,1mte=t med,1mb%ob %ongte=t %ongb%ob

Date Data Types Description date&####-mm-dd* <o%ds date and6or t,me datet,me&####-mm-dd hh2mm2ss* t,mestamp&####mmddhhmmss* t,me&hh2mm2ss* Misc. Data Types en1m&9a%1e1(9a%1e2(e!t* Description E8BC ,s short -or E8BCERATED %,st. Can store one o- 1p to ?::): 9a%1es %,sted >,th,n the & * bra!Dets. E- a 9a%1e ,s ,nserted that ,s not ,n the %,st( a b%anD 9a%1e >,%% be ,nserted SET ,s s,m,%ar to E8BC. <o>e9er( SET !an ha9e 1p to ?4 %,st ,tems and !an store more than one !ho,!e

set

Primary Keys dan uto !ncrement "ields

s$% " 'CREATE TAB5E Person & personED ,nt 8FT 8B55 ABTF_E8CRECE8T( PRECARG HEG&personED*( 7,rst8ame 9ar!har&1:*( 5ast8ame 9ar!har&1:*( Age ,nt *'+ m#s$%_$1er#& s$%( !on*+

You might also like