[PHP-DB] Creating tables
Hi everyone I am using a website based in the states to which is PHP enabled. I am using MySQL. Is there a way to create a table with PHP? I do not see any command for that. I have loaded MySQL for Windows but the server runs MySQL on Unix. I don't know if the file structure is different. Maybe that is why I can not read it? Thanks Herman Wapenaar -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Creating tables
At 08:00 AM 4/25/01 +0200, Herman Wapenaar wrote: I am using a website based in the states to which is PHP enabled. I am using MySQL. Is there a way to create a table with PHP? I do not see any command for that. Well, as an Oracle administrator, I may be going out on a limb here regarding MySQL, but doesn't it accept standard SQL syntax to create, alter or drop tables? CREATE TABLE abc AS SELECT * FROM def WHERE ghi LIKE '%jkl'; (to copy some elements from one table to a new table) CREATE TABLE test (col1 NUMBER NOT NULL PRIMARY KEY, col2 CHAR(2) NOT NULL); ALTER TABLE test ADD col3 NUMBER(5) NOT NULL; DROP TABLE test; - Brian - Brian S. Dunworth Sr. Software Development Engineer Oracle Database Administrator The Printing House, Ltd. (850) 875-1500 x225 [EMAIL PROTECTED] - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Creating tables
Check your MySQL docs for exact syntax on table creation ... then: Connect to the database Build a SQL statement that does what you want: $sql = CREATE TABLE blah, blah ..; Execute the statement: $result = mysql_query( $sql ); and check for errors, etc. Alternately, if this is a Linux box and you can get telnet or SSH access (TerraTermSSH from Windows) you can execute this code directly Miles At 08:00 AM 4/25/01 +0200, Herman Wapenaar wrote: Hi everyone I am using a website based in the states to which is PHP enabled. I am using MySQL. Is there a way to create a table with PHP? I do not see any command for that. I have loaded MySQL for Windows but the server runs MySQL on Unix. I don't know if the file structure is different. Maybe that is why I can not read it? Thanks Herman Wapenaar -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Creating tables
Hi Herman, I am myself a pro at PHP, but I think, this would be of some help to you. To create a Table, you won't find a comand in PHP. However what you do is build a CREATE TABLE statement and pass that as an argument to mysql_query() function to do the job. Here is a small example: mysql_connect($dbhost,$dbuser,$dbpassword) or die(Couldn't Connect); mysql_select_db($dbname); $query = CREATE TABLE YOUR_TABLE ( COL1 INT NOT NULL PRIMARY KEY, COL2 TEXT ); mysql_query($query) or die(mysql_error); Just a small tip. You can use phpmyadmin utility to these sorts of job in a jiffy. I hope this helps! Subodh Gupta I have learned, Joy is not in things, it is in us. You will ultimately be known by what you give and not what you get. - Original Message - From: Herman Wapenaar [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, April 25, 2001 11:30 AM Subject: [PHP-DB] Creating tables Hi everyone I am using a website based in the states to which is PHP enabled. I am using MySQL. Is there a way to create a table with PHP? I do not see any command for that. I have loaded MySQL for Windows but the server runs MySQL on Unix. I don't know if the file structure is different. Maybe that is why I can not read it? Thanks Herman Wapenaar -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Creating tables
Hi Herman, Try something like this... $dbname = my_db; $tablename = my_table; $table_def = item_id MEDIUMINT DEFAULT '0' NOT NULL AUTO_INCREMENT,; $table_def .= item_name VARCHAR(50) BINARY NOT NULL,; $table_def .= lastaccessed TIMESTAMP(14),; $table_def .= PRIMARY KEY (item_id),; $table_def .= UNIQUE item_id (item_id); if(!mysql_select_db($dbname)) die; if(!mysql_query(CREATE TABLE $tablename ($table_def))) die; It's not the prettiest code in the world, I am sure of that. But it should give you a start. I hope this helps! -Original Message- From: Herman Wapenaar [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 24, 2001 11:00 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Creating tables Hi everyone I am using a website based in the states to which is PHP enabled. I am using MySQL. Is there a way to create a table with PHP? I do not see any command for that. I have loaded MySQL for Windows but the server runs MySQL on Unix. I don't know if the file structure is different. Maybe that is why I can not read it? Thanks Herman Wapenaar -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]