LemonInflux Posted October 23, 2007 Share Posted October 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74472-populate-with-sql/ Share on other sites More sharing options...
only one Posted October 23, 2007 Share Posted October 23, 2007 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 ;" ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74472-populate-with-sql/#findComment-376317 Share on other sites More sharing options...
LemonInflux Posted October 23, 2007 Author Share Posted October 23, 2007 yeah but, I've seen people do it with just an .sql file, but I can't remember how. Surely I could just call the file somehow? Quote Link to comment https://forums.phpfreaks.com/topic/74472-populate-with-sql/#findComment-376318 Share on other sites More sharing options...
only one Posted October 23, 2007 Share Posted October 23, 2007 <?php $query = file_get_contents("create.sql"); mysql_query("$query"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74472-populate-with-sql/#findComment-376322 Share on other sites More sharing options...
GingerRobot Posted October 23, 2007 Share Posted October 23, 2007 I would think you will either need to open the file and split the file into individual queries, or use the mysqli extension. The ordinary mysql extention does not support multiple queries. Quote Link to comment https://forums.phpfreaks.com/topic/74472-populate-with-sql/#findComment-376356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.