Jump to content

Recommended Posts

I have a file called create.sql. Inside is this:

 

CREATE TABLE `categories` (
  `cat_id` int(11) NOT NULL auto_increment,
  `cat_name` varchar(30) default NULL,
  PRIMARY KEY  (`cat_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

CREATE TABLE `forums` (
  `forumid` int(11) NOT NULL auto_increment,
  `forum_name` varchar(20) default NULL,
  `forum_desc` varchar(60) default NULL,
  `cat_id` int(11) NOT NULL,
  PRIMARY KEY  (`forumid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

CREATE TABLE `members` (
  `userid` int(11) NOT NULL auto_increment,
  `username` varchar(12) default NULL,
  `password` varchar(100) default NULL,
  `posts` int(11) default NULL,
  `avatar` varchar(255) default NULL,
  `signature` varchar(400) default NULL,
  `msn` varchar(40) default NULL,
  `aim` varchar(100) default NULL,
  `website` varchar(255) default NULL,
  `IP` varchar(20) default NULL,
  `email` varchar(60) default NULL,
  `rank` tinyint(4) NOT NULL,
  `last active` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `birthday` date default NULL,
  `location` varchar(50) default NULL,
  `interests` varchar(200) default NULL,
  `title` varchar(20) default NULL,
  PRIMARY KEY  (`userid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

CREATE TABLE `news` (
  `newsid` int(11) NOT NULL auto_increment,
  `news` text,
  `poster` varchar(12) NOT NULL,
  PRIMARY KEY  (`newsid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;

CREATE TABLE `pm` (
  `pm_id` int(10) unsigned NOT NULL auto_increment,
  `to` varchar(12) default NULL,
  `from` varchar(12) default NULL,
  `subject` varchar(30) default NULL,
  `message` varchar(1000) default NULL,
  PRIMARY KEY  (`pm_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;

CREATE TABLE `posts` (
  `postid` int(10) NOT NULL auto_increment,
  `poster` text NOT NULL,
  `post` varchar(500) default NULL,
  `topicid` int(11) NOT NULL,
  PRIMARY KEY  (`postid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

CREATE TABLE `topics` (
  `topicid` int(11) NOT NULL auto_increment,
  `topic_name` varchar(30) default NULL,
  `topic_desc` varchar(50) default NULL,
  `poster` varchar(12) default NULL,
  `forumid` int(11) NOT NULL,
  PRIMARY KEY  (`topicid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

 

How do I call this file in a php script? I've used mysql_connect and mysql_select_db, and now I need to create tables.

Link to comment
https://forums.phpfreaks.com/topic/74472-populate-with-sql/
Share on other sites

Try this:

<?php
mysql_query("
CREATE TABLE `categories` (
  `cat_id` int(11) NOT NULL auto_increment,
  `cat_name` varchar(30) default NULL,
  PRIMARY KEY  (`cat_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

CREATE TABLE `forums` (
  `forumid` int(11) NOT NULL auto_increment,
  `forum_name` varchar(20) default NULL,
  `forum_desc` varchar(60) default NULL,
  `cat_id` int(11) NOT NULL,
  PRIMARY KEY  (`forumid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

CREATE TABLE `members` (
  `userid` int(11) NOT NULL auto_increment,
  `username` varchar(12) default NULL,
  `password` varchar(100) default NULL,
  `posts` int(11) default NULL,
  `avatar` varchar(255) default NULL,
  `signature` varchar(400) default NULL,
  `msn` varchar(40) default NULL,
  `aim` varchar(100) default NULL,
  `website` varchar(255) default NULL,
  `IP` varchar(20) default NULL,
  `email` varchar(60) default NULL,
  `rank` tinyint(4) NOT NULL,
  `last active` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `birthday` date default NULL,
  `location` varchar(50) default NULL,
  `interests` varchar(200) default NULL,
  `title` varchar(20) default NULL,
  PRIMARY KEY  (`userid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

CREATE TABLE `news` (
  `newsid` int(11) NOT NULL auto_increment,
  `news` text,
  `poster` varchar(12) NOT NULL,
  PRIMARY KEY  (`newsid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;

CREATE TABLE `pm` (
  `pm_id` int(10) unsigned NOT NULL auto_increment,
  `to` varchar(12) default NULL,
  `from` varchar(12) default NULL,
  `subject` varchar(30) default NULL,
  `message` varchar(1000) default NULL,
  PRIMARY KEY  (`pm_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;

CREATE TABLE `posts` (
  `postid` int(10) NOT NULL auto_increment,
  `poster` text NOT NULL,
  `post` varchar(500) default NULL,
  `topicid` int(11) NOT NULL,
  PRIMARY KEY  (`postid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

CREATE TABLE `topics` (
  `topicid` int(11) NOT NULL auto_increment,
  `topic_name` varchar(30) default NULL,
  `topic_desc` varchar(50) default NULL,
  `poster` varchar(12) default NULL,
  `forumid` int(11) NOT NULL,
  PRIMARY KEY  (`topicid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;"
);
?>

Link to comment
https://forums.phpfreaks.com/topic/74472-populate-with-sql/#findComment-376317
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.