Skip to content

Instantly share code, notes, and snippets.

@andreyserdjuk
Created October 19, 2014 16:11
Show Gist options
  • Save andreyserdjuk/71a60eca241178e7e3cd to your computer and use it in GitHub Desktop.
Save andreyserdjuk/71a60eca241178e7e3cd to your computer and use it in GitHub Desktop.
mysql_real_escape_string alternative (analogue)
<?php
// mysql_real_escape_string requires an active mysql connection
function mysqlPrepareStr($str) {
return "'". str_replace(
array( '\\', "\0", "\n", "\r", "'", '"', "\x1a" ),
array( '\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z' ),
$str ) . "'";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment