I have a mySQL table which I need to export the data from into a new table in another database. The table includes a field which is "longtext". I have written a PHP script to take the data from one table and insert it into the other. The script has worked flawlessly until I came to this table which has a "longtext" field. I cannot get that field to copy regardless of what I try. Any suggestions??? HELP!!!! :)
Sep 16, 2003, 12:45 PM
Veteran / Moderator (18441 posts)
Sep 16, 2003, 12:45 PM
Post #2 of 12
Views: 21984
Any particular reason why its a longtext? Surely TEXT could do the job? Or does it hold a *very* long string?
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Sep 16, 2003, 12:49 PM
Veteran / Moderator (18441 posts)
Sep 16, 2003, 12:49 PM
Post #4 of 12
Views: 22049
Mmmm... what query's etc are you using to try and copy it currently?
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Sep 16, 2003, 12:54 PM
User (154 posts)
Sep 16, 2003, 12:54 PM
Post #5 of 12
Views: 21982
$query = "SELECT * FROM profile";
$result = create_db_connection("departments",$query);
while ($row = mysql_fetch_array($result)) {
$query1 = "INSERT INTO department (FIELD1, FIELD2, FIELD3 ...) VALUES (\"$row[field1]\",\"$row[field2]\",\"$row[field3]\" ...)";
$result1 = create_db_connection("new_table",$query1);
} // end while statement
When I remove the last field (which is the longtext field) this script works fine. I thought maybe it had to do with quotation marks and apostraphe's, etc. embedded in the variable; however I have even escaped all those characters and it still errors out.
$result = create_db_connection("departments",$query);
while ($row = mysql_fetch_array($result)) {
$query1 = "INSERT INTO department (FIELD1, FIELD2, FIELD3 ...) VALUES (\"$row[field1]\",\"$row[field2]\",\"$row[field3]\" ...)";
$result1 = create_db_connection("new_table",$query1);
} // end while statement
When I remove the last field (which is the longtext field) this script works fine. I thought maybe it had to do with quotation marks and apostraphe's, etc. embedded in the variable; however I have even escaped all those characters and it still errors out.
Sep 16, 2003, 12:58 PM
Veteran / Moderator (18441 posts)
Sep 16, 2003, 12:58 PM
Post #6 of 12
Views: 21987
You tried mysql_escape_string() ?
http://es2.php.net/...ql-escape-string.php
Could be some charachters in there that are causing the problems...
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
http://es2.php.net/...ql-escape-string.php
Could be some charachters in there that are causing the problems...
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Sep 16, 2003, 1:00 PM
Veteran / Moderator (18441 posts)
Sep 16, 2003, 1:00 PM
Post #8 of 12
Views: 21971
Also, why are you doing stuff like;
(\"$row[field1]\",\
???
You can simply do....
$query1 = "INSERT INTO department (FIELD1, FIELD2, FIELD3 ...) VALUES ('$row[field1]','$row[field2]','$row[field3]' ...)";
PHP isn't fussy about using '' around a string (unlike Perl).
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
(\"$row[field1]\",\
???
You can simply do....
$query1 = "INSERT INTO department (FIELD1, FIELD2, FIELD3 ...) VALUES ('$row[field1]','$row[field2]','$row[field3]' ...)";
PHP isn't fussy about using '' around a string (unlike Perl).
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Sep 16, 2003, 1:04 PM
Veteran / Moderator (18441 posts)
Sep 16, 2003, 1:04 PM
Post #10 of 12
Views: 22067
You got any error catching in there?
Try something like...
my $error = mysql_error();
if ($error) {
echo "SQL Error: <font color=red>$error</font>"; exit;
}
May help to determine a bit more what the SQL error is.
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Try something like...
Code:
$result1 = create_db_connection('new_table',$query1); my $error = mysql_error();
if ($error) {
echo "SQL Error: <font color=red>$error</font>"; exit;
}
May help to determine a bit more what the SQL error is.
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Sep 16, 2003, 1:08 PM
Veteran / Moderator (18441 posts)
Sep 16, 2003, 1:08 PM
Post #12 of 12
Views: 21944
Glad to hear you got it working :) BTW, I would still recommend that mysql_error() code.. there is always the odd random string that will get through, and cause a MySQL error (as I have found out the hard way...lol).
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Cheers
Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!