Re: [PHP] How do i replace table names?
Bas wrote: I want to replace something like this: $sql = "CREATE TABLE bas_table ( )"; With this: "CREATE TABLE hugo_table ( )"; And do the same for INSERT INTO... How do i do this? If you know that "bas_" will not appear within your data, then a simple str_replace() will do. $new_data = str_replace('bas_','dummy_',$old_data); If you're not sure, then a regular expression or more inclusive str_replace() would be necessary. $new_data = str_replace('CREATE TABLE bas','CREATE TABLE dummy',$old_data); or $new_data = preg_replace('^CREATE TABLE bas','CREATE TABLE dummy',$old_data); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How do i replace table names?
[snip] I AM NOT THAT DUMB... I JUST WANT TO REPLACE 1 TABLE PREFIX BY ANOTHER!!! [/snip] http://www.php.net/str_replace -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do i replace table names?
On Mon, Nov 03, 2003 at 04:37:41PM +0100, Bas wrote: > OKAY, I WANT TO REPLACE IN THE TABLENAME THE TEXT BAS_ WITH DUMMY_ > > SUCH LIKE THAT "CREATE TABLE BAS_DATA" BECOMES "CREATE TABLE DUMMY_DATA" > > I AM NOT THAT DUMB... I JUST WANT TO REPLACE 1 TABLE PREFIX BY ANOTHER!!! sed -i.bak -e s'/BAS_/DUMMY_/g' your_sql_file.sql -- zhuravlev alexander u l s t u n o c -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How do i replace table names?
[snip] OKAY, I WANT TO REPLACE IN THE TABLENAME THE TEXT BAS_ WITH DUMMY_ SUCH LIKE THAT "CREATE TABLE BAS_DATA" BECOMES "CREATE TABLE DUMMY_DATA" I AM NOT THAT DUMB... I JUST WANT TO REPLACE 1 TABLE PREFIX BY ANOTHER!!! [/snip] Then do it! And quit top posting! And quit yelling! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do i replace table names?
OKAY, I WANT TO REPLACE IN THE TABLENAME THE TEXT BAS_ WITH DUMMY_ SUCH LIKE THAT "CREATE TABLE BAS_DATA" BECOMES "CREATE TABLE DUMMY_DATA" I AM NOT THAT DUMB... I JUST WANT TO REPLACE 1 TABLE PREFIX BY ANOTHER!!! "Jay Blanchard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] [snip] No, i mean to replace the names in the string... And then execute them... [snip] *slaps forehead* Duh, just do it? $sqlCreateTable = "CREATE TABLE `dumBas` ( "; $sqlCreateTable .= "`ai` int(11) NOT NULL AUTO_INCREMENT, "; $sqlCreateTable .= "`thing` char(32) default NULL, "; $sqlCreateTable .= "`stuff` char(16) default NULL, "; $sqlCreateTable .= "PRIMARY KEY (`ai`), "; $sqlCreateTable .= "KEY `thing` (`thing`) "; $sqlCreateTable .= ") "; $dbCreateTable = mysql_query($sqlCreateTable, $connectionStuff); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How do i replace table names?
[snip] No, i mean to replace the names in the string... And then execute them... [snip] *slaps forehead* Duh, just do it? $sqlCreateTable = "CREATE TABLE `dumBas` ( "; $sqlCreateTable .= "`ai` int(11) NOT NULL AUTO_INCREMENT, "; $sqlCreateTable .= "`thing` char(32) default NULL, "; $sqlCreateTable .= "`stuff` char(16) default NULL, "; $sqlCreateTable .= "PRIMARY KEY (`ai`), "; $sqlCreateTable .= "KEY `thing` (`thing`) "; $sqlCreateTable .= ") "; $dbCreateTable = mysql_query($sqlCreateTable, $connectionStuff); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do i replace table names?
No, i mean to replace the names in the string... And then execute them... "Jay Blanchard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] [snip] I want to replace something like this: $sql = "CREATE TABLE bas_table ( )"; With this: "CREATE TABLE hugo_table ( )"; And do the same for INSERT INTO... How do i do this? [/snip] Top of the morning to you Bas! I have a couple of questions for you. 1. Have you read any of the manual? 2. Are you subscribed to the MySQL list? All queries are run in the same way. If you have permissions in the database you can do this (for example); $sqlInsert = "INSERT INTO tableBAS (php, mysql) ": $sqlInsert .= "VALUES ('knowledge from having read PHP manual', "; $sqlInsert .= "'knowledge from having read MySQL manual') "; $dbInsert = mysql_query($sqlInsert, $connectionInformation); HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How do i replace table names?
[snip] I want to replace something like this: $sql = "CREATE TABLE bas_table ( )"; With this: "CREATE TABLE hugo_table ( )"; And do the same for INSERT INTO... How do i do this? [/snip] Top of the morning to you Bas! I have a couple of questions for you. 1. Have you read any of the manual? 2. Are you subscribed to the MySQL list? All queries are run in the same way. If you have permissions in the database you can do this (for example); $sqlInsert = "INSERT INTO tableBAS (php, mysql) ": $sqlInsert .= "VALUES ('knowledge from having read PHP manual', "; $sqlInsert .= "'knowledge from having read MySQL manual') "; $dbInsert = mysql_query($sqlInsert, $connectionInformation); HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do i replace table names?
I want to replace something like this: $sql = "CREATE TABLE bas_table ( )"; With this: "CREATE TABLE hugo_table ( )"; And do the same for INSERT INTO... How do i do this? Regards, Bas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php