Skip to:
Content

bbPress.org

Changeset 906


Ignore:
Timestamp:
07/13/2007 11:27:06 PM (19 years ago)
Author:
mdawaffe
Message:

prepare() method for DB. See #WP4553

Location:
trunk/bb-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/db-mysqli.php

    r790 r906  
    139139        function escape_deep( $array ) {
    140140                return is_array($array) ? array_map(array(&$this, 'escape_deep'), $array) : $this->escape( $array );
     141        }
     142
     143        /**
     144         * Escapes content by reference for insertion into the database, for security
     145         * @param string $s
     146         */
     147        function escape_by_ref(&$s) {
     148                $s = $this->escape($s);
     149        }
     150
     151        /**
     152         * Prepares a SQL query for safe use, using sprintf() syntax
     153         */
     154        function prepare($args=NULL) {
     155                if ( NULL === $args )
     156                        return;
     157                $args = func_get_args();
     158                $query = array_shift($args);
     159                $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it
     160                $query = str_replace('"%s"', '%s', $query); // doublequote unquoting
     161                $query = str_replace('%s', "'%s'", $query); // quote the strings
     162                array_walk($args, array(&$this, 'escape_by_ref'));
     163                return @vsprintf($query, $args);
    141164        }
    142165
  • trunk/bb-includes/db.php

    r733 r906  
    132132        function escape_deep( $array ) {
    133133                return is_array($array) ? array_map(array(&$this, 'escape_deep'), $array) : $this->escape( $array );
     134        }
     135
     136        /**
     137         * Escapes content by reference for insertion into the database, for security
     138         * @param string $s
     139         */
     140        function escape_by_ref(&$s) {
     141                $s = $this->escape($s);
     142        }
     143
     144        /**
     145         * Prepares a SQL query for safe use, using sprintf() syntax
     146         */
     147        function prepare($args=NULL) {
     148                if ( NULL === $args )
     149                        return;
     150                $args = func_get_args();
     151                $query = array_shift($args);
     152                $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it
     153                $query = str_replace('"%s"', '%s', $query); // doublequote unquoting
     154                $query = str_replace('%s', "'%s'", $query); // quote the strings
     155                array_walk($args, array(&$this, 'escape_by_ref'));
     156                return @vsprintf($query, $args);
    134157        }
    135158
Note: See TracChangeset for help on using the changeset viewer.