SitePoint Sponsor |
|
User Tag List
Results 1 to 1 of 1
Thread: copying and moving a string
-
Nov 23, 2004, 08:42 #1
- Join Date
- Nov 2004
- Location
- stoke
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
copying and moving a string
Hi,
i am an extreme newbie to this forum and this php malarky, and am in need of some help.my main problem is that I need help converting the syntax from mssql to mysql, im trying to do it a php script so it will save time.
I want it to read the stuff in from a file, chnage the syntax so its valid and then write the correct syntax to another file. i have done the reading and the writing to files from the above code but the main problem(s) are:
1. i need to add the name to the end of the 'CREATE TABLES' as well of where it is. Also in this case where [DEPENDANCY ID] is, the IDENTITY(1, 1) may not be on the 1st create table line so i need to to search each 'block of mysql code' to find out which column IDENTITY(1, 1) belongs to and then to add it to the end.
Code:CREATE TABLE [dbo].[NimoiModuleDependencies] ( [DependencyID] [int] IDENTITY (1, 1) NOT NULL , [BaseModuleIDList] [nvarchar] (200) NOT NULL , [TopModuleID] [int] NOT NULL , [ORDependencyID] [bit] NOT NULL ) ON [PRIMARY] GO
Code:CREATE TABLE NimoiModuleDependencies ( DependencyID INT NOT NULL AUTO_INCREMENT , BaseModuleIDList VARCHAR(200) NOT NULL , TopModuleID INT NOT NULL , ORDependencyID BIT NOT NULL, ON PRIMARY KEY (DependencyID) );
Here is my PHP code
PHP Code:<?php
$filename = "text1.txt";
$fp = fopen($filename, "r");
//fread function -contain 2 parameters 1 fpopen function 2 filesize
$fileread = fread($fp,filesize($filename));
fclose($fp);
$str = str_replace("[int]","INT",$fileread);
$str = str_replace("[dbo].","", $str);
$str = str_replace("[bit]","BIT",$str);
$str = str_replace("[nvarchar]","VARCHAR",$str);
$str = str_replace("VARCHAR (200)","VARCHAR(200)",$str);
$str = str_replace("CHAR (10)","CHAR(10)",$str);
$str = str_replace("ON [PRIMARY]","PRIMARY KEY(id))",$str);
$str = str_replace("GO","",$str);
$MySQL = "$str";
$filename = "text2.txt";
$fp = fopen("$filename","a");
If (!$fp) {
print "error! cant be opened";
exit;
}
$stringtowrite=$MySQL;
$filewrite = fwrite($fp, $stringtowrite);
$fclose = fclose($fp);
print "written <br><br>$stringtowrite ";
?>
Thanks for your help guys its much appreciated.
Andy
Bookmarks