views:

31

answers:

2

I have following piece of code which posts some data into database:

$post = trim( $post );
$post = htmlentities( $post, ENT_QUOTES, null, false );

$statement = "INSERT INTO table (row) VALUES (:message)";
$prepared_posts = $pdo->prepare( $statement );
$prepared_posts->execute( array( ':message' => $post ) );

I have MySQL version 5.1.47-community on both localhost and staging / production server, but I'm getting different output on both of them. On localhost I'm running PHP 5.3.2, production server has PHP 5.2.14.

If I'm trying to post sentence that's "ok", on production it saves that\'s \"ok\", localhost produces correct that's "ok".

What could be causing this? Could it be some MySQL setting? I also tried using mysqli instead of PDO and it does the same thing.

+1  A: 

These additional backslashes could be Magic Quotes so that that's "ok" becomes that\'s \"ok\". Try to disable them.

Gumbo
Thanks for fast solution!
Ondrej Slinták
A: 

I suppose that magic_quotes_gpc is on in production server and in localhost is off.

You can set it using ini_set command.

rahim asgari
In fact, manual says you cannot set it using ini_set, but there's a workaround for disabling it at runtime.
Ondrej Slinták