Click to See Complete Forum and Search --> : Quotes in MySQL
dclamp
Oct 15th, 2006, 11:04 PM
How come when i put quotes into MySQL it displays with backslashes?
kows
Oct 16th, 2006, 12:08 AM
uhh. put them in how?
it won't add backslashes to anything unless you do it yourself using some function.
CornedBee
Oct 16th, 2006, 02:00 AM
Yes it will, if you use the magic_quotes misfeature. (It's enabled by default on most PHP installations.)
dclamp
Oct 16th, 2006, 07:30 PM
Yes it will, if you use the magic_quotes misfeature. (It's enabled by default on most PHP installations.)
how do you reverse this mis-feature?
hairball
Oct 16th, 2006, 08:31 PM
You can change it in php.ini
It looks something like this:
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = On
; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off
; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off
or you can use the stripslashes (http://se2.php.net/stripslashes) function.
dclamp
Oct 16th, 2006, 09:25 PM
where is the php.ini located?
hairball
Oct 16th, 2006, 09:43 PM
If you are using Windows... it's either under Windows directory or your PHP directory.
If you are using Linux... try the command: locate php.ini
Mine is located in /usr/local/php/lib/php.ini
Before you try editing anything. Backup a copy.
Restart your server after editing php.ini for changes to take effect.
kows
Oct 16th, 2006, 09:44 PM
if your website is using a shared web hosting plan, you can probably -not- change the php.ini. you can try putting a ticket in to petition the option being changed, but other than that you are probably out of luck in that department. i did some looking around in the php functions, but couldn't find anything to disable magic_quotes_gpc.
however, by default, on windows systems the ini file is installed to C:/Windows/
dclamp
Oct 16th, 2006, 09:52 PM
i am using cpanel and it says that i have "FreeBSD". and my hosting company sucks so they will not want to help me. lol. I will try to see if they will change it for me. Yeah, i am on shared hosting -unfortunanly-
kows
Oct 16th, 2006, 09:57 PM
FreeBSD is a Unix based OS, but since you are on a shared hosting plan I highly doubt you can run any type of Unix command to find the files. the most you can do is send in a ticket and ask if they can change it (although I doubt they would, because with most shared webhosting plans, multiple accounts are using the same ini file on a given server, and a change like that could possibly break someone else's website.. might turn into some kind of vote thing for the accounts on that server, though..), otherwise you'll just have to remove the slashes yourself through functions.
CornedBee
Oct 17th, 2006, 06:55 AM
Here's how to reverse the effect of magic_quotes: include this snippet at the top of every PHP file:
if(get_magic_quotes_gpc()) {
foreach($_GET as $k => $v) {
$_GET[$k] = stripslashes($v);
}
foreach($_POST as $k => $v) {
$_POST[$k] = stripslashes($v);
}
foreach($_COOKIE as $k => $v) {
$_COOKIE[$k] = stripslashes($v);
}
}
penagate
Oct 17th, 2006, 09:18 AM
Here's how to reverse the effect of magic_quotes: include this snippet at the top of every PHP file:
if(get_magic_quotes_gpc()) {
foreach($_GET as $k => $v) {
$_GET[$k] = stripslashes($v);
}
foreach($_POST as $k => $v) {
$_POST[$k] = stripslashes($v);
}
foreach($_COOKIE as $k => $v) {
$_COOKIE[$k] = stripslashes($v);
}
}
Unfortunately that only does a shallow reverse and magic quotes is a deep operation, so you will need something more like this:
if (get_magic_quotes_gpc()) {
array_walk_recursive($_GET, $rv_func = create_function('$n', 'stripslashes($n);'));
array_walk_recursive($_POST, $rv_func);
array_walk_recursive($_COOKIE, $rv_func);
}
There are also some other things that are affected by it, can't remember them off the top of my head right now.
CornedBee
Oct 17th, 2006, 11:29 AM
Didn't know it was recursive, though of course that makes sense. Good call.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.