db.js
/**
 * Escapes potentiall dangerous characters with backslashes, to be used in SQL statements.
 * @param {String} str Input string
 * @returns String with all characters that are potentially dangerous to SQL escaped with backslashes
 */
Escapes potentiall dangerous characters with backslashes, to be used in SQL statements.
@param {String} str Input string
@returns String with all characters that are potentially dangerous to SQL escaped with backslashes
Escapes potentiall dangerous characters with backslashes to be used in SQL statements . @param { String } str Input string @returns String with all characters that are potentially dangerous to SQL escaped with backslashes
function mysql_real_escape_string (str) {
  if (typeof str != 'string') return str; 
  return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
      switch (char) {
          case "\0":
              return "\\0";
          case "\x08":
              return "\\b";
          case "\x09":
              return "\\t";
          case "\x1a":
              return "\\z";
          case "\n":
              return "\\n";
          case "\r":
              return "\\r";
          case "\"": 
          case "'":  
          case "\\": 
          case "%":  
              return "\\" + char; 
      }
  });
}
function mysql_real_escape_string ( str ) { if ( typeof str != 'string' ) return str ; return str . replace ( / [\0\x08\x09\x1a\n\r"'\\\%] / g , function ( char ) { switch ( char ) { case "\0" : return "\\0" ; case "\x08" : return "\\b" ; case "\x09" : return "\\t" ; case "\x1a" : return "\\z" ; case "\n" : return "\\n" ; case "\r" : return "\\r" ; case "\"" : case "'" : case "\\" : case "%" : return "\\" + char ; } } ) ; }
Escapes potentiall dangerous characters with backslashes, to be used in SQL statements.
Escapes potentiall dangerous characters with backslashes to be used in SQL statements .
// If the inputted value is not a string, just return that value // Fall through to case "%" // Fall through to case "%" // Fall through to case "%" // Fall through to case "%" // prepends a backslash to backslash, percent, // and double/single quotes