Does anyone have a code snippet for...
Moderator: General Moderators
feyd wrote:No. It separates them so you can run them individually using a loop and whatever query interface you are using.
uhm, so I put this in the script and it should work then?
Code: Select all
preg_match_all('/^#([^#]+)#$/',$str10,$matches);
print_r($matches);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
That's not the code I posted later in the thread.
this is.
this is.
Code: Select all
<?php
preg_match_all('@^(?![\s#])\s*((?s:.*?))\s*;\s*$@m',$text,$matches);
print_r($matches);
?>But on the that thread you put it in one file where the queries were also places in, but where do I have to put it now, in insert.php or the query file? because when I put it in insert.php i get thisfeyd wrote:That's not the code I posted later in the thread.
this is.Code: Select all
<?php preg_match_all('@^(?![\s#])\s*((?s:.*?))\s*;\s*$@m',$text,$matches); print_r($matches); ?>
and in the .sql it stays the same = /Array ( [0] => Array ( ) [1] => Array ( ) ) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; # ---------- CREATE TABLE `Table1` ---------- CREATE TABLE `Table1` ( `ID` ' at line 6
Well, the code reads .sql files like thisfeyd wrote:It's extremely simple.
How did you set $text with the contents of the .sql file?
Code: Select all
$sqlfile = "punten.sql";
$handle = fopen($sqlfile, "r");
$sql_query = fread($handle, filesize($sqlfile));
fclose($handle);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I am unable to produce your errors...output
Code: Select all
<?php
$text = file_get_contents('punten.sql');
preg_match_all('@^(?![\s#])\s*((?s:.*?))\s*;\s*$@m',$text,$matches);
print_r($matches);
?>Code: Select all
# ---------- MdbToMySQL XP 0.9 MySQL IMPORT FROM `C:\Documents and Settings\Owner\Desktop\Punten.mdb` ----------
# ---------- DROP TABLE `Table1` BEFORE (RE)CREATION ----------
DROP TABLE IF EXISTS `Table1`;
# ---------- CREATE TABLE `Table1` ----------
CREATE TABLE `Table1` (
`ID` INT NOT NULL AUTO_INCREMENT,
`Naam` VARCHAR(255) NULL,
`Toets_Hsft_1` VARCHAR(255) NULL,
`Toets_Hsft_2` INT NULL,
`Toets_Hsft_3` INT NULL,
`HSFT_4` INT NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM;
# ---------- EMPTY TABLE `Table1` ----------
DELETE FROM `Table1`;
# ---------- POPUPLATE TABLE `Table1` ----------
INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (2, 'Calvin', '6', 8, 5, 5);
INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (3, 'Jenna', '6', 4, 4, 2);
INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (4, 'Puri', '4', 8, 6, 8);
INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (5, 'Wakamoli', '8', 9, 8, 6);
INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (6, 'yakuma', '9', 4, 5, 4);
INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (7, 'Gizaki', '2', 5, 8, 5);
INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (8, 'Mankala', '3', 6, 10, 2);
# ---------- END OF IMPORT FROM `C:\Documents and Settings\Owner\Desktop\Punten.mdb` ----------Code: Select all
Array
(
[0] => Array
(
[0] => DROP TABLE IF EXISTS `Table1`;
[1] => CREATE TABLE `Table1` (
`ID` INT NOT NULL AUTO_INCREMENT,
`Naam` VARCHAR(255) NULL,
`Toets_Hsft_1` VARCHAR(255) NULL,
`Toets_Hsft_2` INT NULL,
`Toets_Hsft_3` INT NULL,
`HSFT_4` INT NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM;
[2] => DELETE FROM `Table1`;
[3] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (2, 'Calvin', '6', 8, 5, 5);
[4] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (3, 'Jenna', '6', 4, 4, 2);
[5] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (4, 'Puri', '4', 8, 6, 8);
[6] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (5, 'Wakamoli', '8', 9, 8, 6);
[7] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (6, 'yakuma', '9', 4, 5, 4);
[8] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (7, 'Gizaki', '2', 5, 8, 5);
[9] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (8, 'Mankala', '3', 6, 10, 2);
)
[1] => Array
(
[0] => DROP TABLE IF EXISTS `Table1`
[1] => CREATE TABLE `Table1` (
`ID` INT NOT NULL AUTO_INCREMENT,
`Naam` VARCHAR(255) NULL,
`Toets_Hsft_1` VARCHAR(255) NULL,
`Toets_Hsft_2` INT NULL,
`Toets_Hsft_3` INT NULL,
`HSFT_4` INT NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM
[2] => DELETE FROM `Table1`
[3] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (2, 'Calvin', '6', 8, 5, 5)
[4] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (3, 'Jenna', '6', 4, 4, 2)
[5] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (4, 'Puri', '4', 8, 6, 8)
[6] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (5, 'Wakamoli', '8', 9, 8, 6)
[7] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (6, 'yakuma', '9', 4, 5, 4)
[8] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (7, 'Gizaki', '2', 5, 8, 5)
[9] => INSERT INTO `Table1` (`ID`, `Naam`, `Toets_Hsft_1`, `Toets_Hsft_2`, `Toets_Hsft_3`, `HSFT_4`) VALUES (8, 'Mankala', '3', 6, 10, 2)
)
)Hmm, then maybe im Doing soemthing wrong
I'm currently palcing this in insert.php
So it comes out as
Is this where I am doing it wrong? because I am getting almost the same result as you, but in the end I get
I'm currently palcing this in insert.php
Code: Select all
<?php
$text = file_get_contents('punten.sql');
preg_match_all('@^(?![\s#])\s*((?s:.*?))\s*;\s*$@m',$text,$matches);
print_r($matches);
?>Code: Select all
<?php
// Open Connection To mySQL.
// Replace 'username' and 'password' with appropiate login values for your server.
$mysqlLink = mysql_connect( 'localhost' , 'username' , 'password' );
// Select mySQL Database.
mysql_select_db( 'database' , $mysqlLink );
// Create Query To Create Table.
$sqlfile = "punten.sql";
$handle = fopen($sqlfile, "r");
$sql_query = fread($handle, filesize($sqlfile));
fclose($handle);
$text = file_get_contents('punten.sql');
preg_match_all('@^(?![\s#])\s*((?s:.*?))\s*;\s*$@m',$text,$matches);
print_r($matches);
// Issue Query.
mysql_query($sql_query, $mysqlLink) or die(mysql_error());
// Close mySQL Connection.
mysql_close( $mysqlLink );
?>And the database isn't updated..You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
# ---------- CREATE TABLE `Table1` ----------
CREATE TABLE `Table1` (
' at line 6
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Do you understand how to make a loop? If you don't, go here: http://php.net/language.control-structures You're interested in the while, do-while, for, and foreach controls.
Provided your queries are valid and do not conflict for some reason, I don't see why they wouldn't work once you get this code functioning correctly.
Provided your queries are valid and do not conflict for some reason, I don't see why they wouldn't work once you get this code functioning correctly.