Important alert: (current site time 7/15/2013 8:52:05 PM EDT)
 

VB icon

Create New MySQL Database

Email
Submitted on: 8/14/2003 3:31:49 PM
By: Mr. Tweed 
Level: Beginner
User Rating: By 3 Users
Compatibility: 5.0 (all versions), Active Perl specific
Views: 17298
 
     This code will create a new MySQL Database.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Create New MySQL Database
= Description:This code will create a new MySQL Database.
= By: Mr. Tweed
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=520&lngWId=6=for details.=**************************************

#!/bin/perl
use Mysql;
use strict;
	
	
my host = '';## MySQL Host
my $user = ''## Your username
my $password = ''; ## Your password
my $database = ''; ## Your Database name you want
	
my $dbh = Msql->connect($host, undef, $user, $password);
	
### Create database.
my $rc = $dbh->createdb($database);
$dbh->selectdb($database);
	
	
my $sql_statement = <<"EndOfSQL";
CREATE TABLE TableContacts (
	ID				COUNTER,
	LastName		CHAR(40),
	FirstName	CHAR(40),
	MiddleName CHAR(20);
	HomePhone	CHAR(40),
	WorkPhone	CHAR(40),
	CellPhone CHAR(40);
	BirthDay CHAR(20);
	Fax			CHAR(40),
	Email			CHAR(40),
	Address1		CHAR(40),
	Address2		CHAR(40),
	City			CHAR(30),
	State			CHAR(10),
	ZipCode		CHAR(20),
CONSTRAINT ID_PK PRIMARY KEY(ID)	
)	
	
my $sth = $dbh->query($sql_statement);
	
	
	
	
	
	
	


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
8/16/2003 8:29:12 AMJason Myerscough

creating mySQL stuff in perl looks easy but is very powerful. :)
(If this comment was disrespectful, please report it.)

 
8/17/2003 5:06:50 AMChris Stratford

Are there any good full tutorials on how to use MySQL in perl?
like how to setup a dbase?
and then use it?
i mean simple tutorials.
I love short code with comments.
thats best!
(If this comment was disrespectful, please report it.)

 
8/18/2003 8:35:13 AMJason Myerscough

my brother(Damian) is currently working on a perl/SQL tutorial so look out for that
(If this comment was disrespectful, please report it.)

 
8/21/2003 9:48:15 AMMoth7

Hmmm...I personally prefer the DBI module but nice code all the same. @Those looking for tutorials: The MySQL cookbook by o'reilly has some nice stuff in it (works through different problems using Perl as 1 of the 4 featured languages) and I'm sure that they wrote a book specifically about Perl with MySQL but I can't remember the title off the top of my head :-\
(If this comment was disrespectful, please report it.)

 
8/23/2004 11:37:19 PM

Can't find string terminator
(If this comment was disrespectful, please report it.)

 
8/23/2004 11:38:20 PM

Can't find string terminator "EndOfSQL" anywhere before EOF at create_table2.pl
line 18.
...what is an error?
(If this comment was disrespectful, please report it.)

 
8/23/2004 11:39:08 PM

Can't find string terminator "EndOfSQL" anywhere before EOF at
create_table2.pl
line 18.
...what is
an error?
(If this comment was disrespectful, please report it.)

 
8/26/2004 6:44:10 AMDave Bushea

After
my $sql_statement = <<
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.