Helpful Information
 
 
Category: vB3 Programming Discussions
*VERY* new to PHP

Hey.

I just started learnin about PHP, from a mate.
He showed my how to do loads of REALLY neat things, but he DIDN'T tell me how to add tables to an SQL database.

Can anyone help me, or point me in the direction of some good tutorials??

HI !

Yuo can use a SQL query:


CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
[table_options] [select_statement]

create_definition:
col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
[PRIMARY KEY] [reference_definition]
or PRIMARY KEY (index_col_name,...)
or KEY [index_name] (index_col_name,...)
or INDEX [index_name] (index_col_name,...)
or UNIQUE [INDEX] [index_name] (index_col_name,...)
or FULLTEXT [INDEX] [index_name] (index_col_name,...)
or [CONSTRAINT symbol] FOREIGN KEY index_name (index_col_name,...)
[reference_definition]
or CHECK (expr)

type:
TINYINT[(length)] [UNSIGNED] [ZEROFILL]
or SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
or MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
or INT[(length)] [UNSIGNED] [ZEROFILL]
or INTEGER[(length)] [UNSIGNED] [ZEROFILL]
or BIGINT[(length)] [UNSIGNED] [ZEROFILL]
or REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
or DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
or FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
or DECIMAL(length,decimals) [UNSIGNED] [ZEROFILL]
or NUMERIC(length,decimals) [UNSIGNED] [ZEROFILL]
or CHAR(length) [BINARY]
or VARCHAR(length) [BINARY]
or DATE
or TIME
or TIMESTAMP
or DATETIME
or TINYBLOB
or BLOB
or MEDIUMBLOB
or LONGBLOB
or TINYTEXT
or TEXT
or MEDIUMTEXT
or LONGTEXT
or ENUM(value1,value2,value3,...)
or SET(value1,value2,value3,...)

index_col_name:
col_name [(length)]

reference_definition:
REFERENCES tbl_name [(index_col_name,...)]
[MATCH FULL | MATCH PARTIAL]
[ON DELETE reference_option]
[ON UPDATE reference_option]

reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT

table_options:
TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM }
or AUTO_INCREMENT = #
or AVG_ROW_LENGTH = #
or CHECKSUM = {0 | 1}
or COMMENT = "string"
or MAX_ROWS = #
or MIN_ROWS = #
or PACK_KEYS = {0 | 1 | DEFAULT}
or PASSWORD = "string"
or DELAY_KEY_WRITE = {0 | 1}
or ROW_FORMAT= { default | dynamic | fixed | compressed }
or RAID_TYPE= {1 | STRIPED | RAID0 } RAID_CHUNKS=# RAID_CHUNKSIZE=#
or UNION = (table_name,[table_name...])
or INSERT_METHOD= {NO | FIRST | LAST }
or DATA DIRECTORY="directory"
or INDEX DIRECTORY="directory"

select_statement:
[IGNORE | REPLACE] SELECT ... (Some legal select statement)





directly with query command.

Ex: if you use MySql you can write this:

<?

#This string to connect database
mysql_pconnect("localhost", "username","password");

#This string to create db
mysql_query("CREATE DATABASE dbexample");

#This string to create TABLE
mysql_query("CREATE TABLE prova (id INT (11) not null , test VARCHAR (255) not null ) ");
?>




PS: For MySql, If you can, install a powerfull php script: "phpMyAdmin".
You can download here:
http://phpmyadmin.sourceforge.net/

See you soon ;)

jJazz

mySQL home (http://www.mysql.com)

search for 'create' (http://www.mysql.com/doc/manual.php?search_query=create&depth=0):
Create Database (http://www.mysql.com/doc/C/R/CREATE_DATABASE.html)
Create Table (http://www.mysql.com/doc/C/R/CREATE_TABLE.html)
Alter Table (http://www.mysql.com/doc/A/L/ALTER_TABLE.html)

Cool

Thanks guys, that helps a lot :D










privacy (GDPR)