How to execute MySQL file through PHP
Moderator: General Moderators
-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
How to execute MySQL file through PHP
What's the query(MySQL) or function(PHP) to execute querys' in an external SQL file?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
They're just stored one after the other, nothing else, maybe some comments. Here's an example:
DROP TABLE IF EXISTS `rp_country`;
CREATE TABLE `rp_country` (
`countryid` tinyint(2) unsigned NOT NULL auto_increment,
`country_symb` char(2) NOT NULL default '',
`country` varchar(27) NOT NULL default '',
PRIMARY KEY (`countryid`)
) TYPE=MyISAM AUTO_INCREMENT=249 ;
That's just something from a SQL file that PhpMyAdmin made. I know they do it, and I know theirs is really complicated. I thought there was a way simple way to do it.
DROP TABLE IF EXISTS `rp_country`;
CREATE TABLE `rp_country` (
`countryid` tinyint(2) unsigned NOT NULL auto_increment,
`country_symb` char(2) NOT NULL default '',
`country` varchar(27) NOT NULL default '',
PRIMARY KEY (`countryid`)
) TYPE=MyISAM AUTO_INCREMENT=249 ;
That's just something from a SQL file that PhpMyAdmin made. I know they do it, and I know theirs is really complicated. I thought there was a way simple way to do it.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
Why can't you just use
That will read your file and execute the query statements within it. If the file is kicked out from phpMyAdmin, which is just acting as a front end for mysqldump anyways, then it should also have a command in there like...
When you get right down to it, the mysql client is rather powerful and flexible. Look at the below.
For the most part, there is no need to write code for this. Just be glad you haven't had to write scripts to parse the output from 3.23.xx binlog files.
Hope that helps,
BDKR
?mysql < your_mysql_file
That will read your file and execute the query statements within it. If the file is kicked out from phpMyAdmin, which is just acting as a front end for mysqldump anyways, then it should also have a command in there like...
... so it knows where to write this information (which database to execute these queries against). If it doesn't, you could type in the commmand as...use your_database;
mysql your_database < your_mysql_file
When you get right down to it, the mysql client is rather powerful and flexible. Look at the below.
You can find the information about it (as well as almost everything else you will need) at mysql.com. Also, those switches work with a good number of the other programs in the bin directory.mysql -h 192.168.0.75 -u you -p -P 4417 your_database < your_mysql_file
For the most part, there is no need to write code for this. Just be glad you haven't had to write scripts to parse the output from 3.23.xx binlog files.
Hope that helps,
BDKR