Current location: Hot Scripts Forums » Programming Languages » PHP » cant add more than 1 mysql table with php script


cant add more than 1 mysql table with php script

Reply
  #1 (permalink)  
Old 04-27-04, 04:13 AM
chrisb62 chrisb62 is offline
New Member
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
cant add more than 1 mysql table with php script

hey.

i'm attampting to have a php script add tables to a mysql database.
it works fine when you have it just add one table. but if you try to add to or more at the same time it doesnt do it.

here is my code:

<?
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to mysql");



$selected = mysql_select_db("$database",$dbh)
or die("Could not select database ($database)");

if (mysql_query("

CREATE TABLE content
(
ID INT NOT NULL AUTO_INCREMENT,
title TEXT NOT NULL,
body TEXT NOT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE links
(
ID INT NOT NULL AUTO_INCREMENT,
page_title TEXT NOT NULL,
link TEXT NOT NULL,
PRIMARY KEY (ID)
);

")) {
print "successfully added tables<br>";
}
else {
print "Failed to add tables<br>";
}
mysql_close($dbh);

?>

it connects to the database fine, like i said it will do it if i only have one CREATE TABLE part in there, but if i have the second one..CREATE LINKS, it doesn't work.

any help would be appreciated

Thanks
Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-27-04, 05:00 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
the old extension of mysql lib doesn't support multi-queries execution! which means that you have to run each CREATE TABEL query in mysql_query() line!

instead you can use the new improved mysql extension known as mysqli !!
but you must have MySQL 4.0 or higher to use this extension ..
more info:
http://www.php.net/manual/en/ref.mysqli.php
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when trying to create MySQL table via PHP HasansWeb PHP 5 05-19-11 07:59 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
How to write a php script to load a text file into a table automatically? xmxpcom PHP 2 02-12-04 09:37 AM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 04:31 AM
PHP + MySQL script help need andyinorbit2000 PHP 1 09-09-03 03:07 AM


All times are GMT -5. The time now is 09:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.