Page 1 of 1
formatting mysql fetch with "'"
Posted: Wed Nov 09, 2005 1:59 pm
by vincenzobar
now i am running into a problem with 's
when i do a fetch_rows and then go to move info to anothe DB it doesn't take the rows that contain words like America's
Here is the code
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$move[] = "'', "."'".implode("', '", $db_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
mysql_query($delete) or die(mysql_error());
}
Where do i or how do i do a addslashes? i triedvarious places but non seemed to work
Posted: Wed Nov 09, 2005 2:30 pm
by Luke
try mysql_real_escape_string() on the input variable
Posted: Wed Nov 09, 2005 2:44 pm
by vincenzobar
everything but the last call is an array for implode to work and if i attach it to the last call it \ all ' and that won't work!!
Arg it's the last step
scheit!!!!!!!!!!!!!!!!!!!!!!!
Posted: Wed Nov 09, 2005 2:48 pm
by Luke
Did you try this?
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$move[] = "'', "."'".implode("', '", $db_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.mysql_real_escape_string($moved).'';
mysql_query($archive) or die(mysql_error());
mysql_query($delete) or die(mysql_error());
}
EDIT: NVM this is wrong... I hang on a minute.
Posted: Wed Nov 09, 2005 2:51 pm
by Luke
Maybe this?
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$move[] = "'', "."'".implode("', '", mysql_real_escape_string($db_row))."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
mysql_query($delete) or die(mysql_error());
}
Posted: Wed Nov 09, 2005 3:42 pm
by vincenzobar
tried that this is the error
mysql_real_escape_string() expects parameter 1 to be string, array given...
everything in there is an array except the last which makes everything \'
there has to be a way around this!!!
Posted: Wed Nov 09, 2005 4:09 pm
by Jenk
You are imploding twice on a one dimensional array?
Anyway..
Code: Select all
array_map('mysql_real_escape_string', $db_row);
Posted: Wed Nov 09, 2005 4:12 pm
by vincenzobar
where does that go and how would you implode it otherwise??
it needs to look like this
('asd', 'asd'), (...), (...)
Posted: Wed Nov 09, 2005 4:18 pm
by vincenzobar
i did this
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
array_map('mysql_real_escape_string', $db_row);
$move[] = "'', "."'".implode("', '", $db_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
//mysql_query($delete) or die(mysql_error());
}
and output still didn't do it
('', '192', 'America's Choice 450', '450', '39.9900.....
wow this is proving difficult!!!
Posted: Wed Nov 09, 2005 4:28 pm
by John Cartwright
Code: Select all
$db_row = array_map('mysql_real_escape_string', $db_row);

Posted: Wed Nov 09, 2005 4:35 pm
by vincenzobar
LOL I feel like a retard... My brain is fried!!
I read over array_map and realized that about 2 seconds after i posted that!!!
code now looks like
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$dbf_row = array_map('mysql_real_escape_string', $db_row);
$move[] = "'', "."'".implode("', '", $dbf_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
//mysql_query($delete) or die(mysql_error());
}
Thanks!