Re: DB_common escapeSimple() not found
| From: | Justin Patrin | Date: | Fri, 04 Nov 2005 01:02:01 +0000 |
| Subject: | Re: DB_common escapeSimple() not found | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21769@lists.php.net to get a copy of this message | ||
On 11/3/05, brian <brian@zijn-digital.com> wrote:
> Justin Patrin wrote:
> > On 11/3/05, brian <brian@zijn-digital.com> wrote:
> >>>> This is pretty strange. PHP refuses to recognize escapeSimple
> >>>> method called from quoteSmart(). This happens whether i call
> >>>> DB_common::quoteSmart() or DB_pgsql::quoteSmart().
> >>>>
> >>>
> >>> Sound slike you may have an upgrade/include_path problem. Use
> >>> get_included_files() to make sure all of the DB stuff is being
> >>> included from the same place.
> >>>
> >> The error is thrown *inside* common.php while attempting to call
> >> the method escapesimple() from quoteSmart(). escapeSimple() is
> >> right there in the source below quoteSmart(). The very same problem
> >> occurs whether i use common.php or pgsql.php.
> >>
> >
> > Just try what I mentioned. In addition, you might want to check for
> > errors.
> >
> An error is exactly what i'm enquiring about. As for included files,
> among others:
>
> string(29) "/usr/local/php/lib/php/DB.php"
> [5]=>
> string(31) "/usr/local/php/lib/php/PEAR.php"
> [6]=>
> string(35) "/usr/local/php/lib/php/DB/pgsql.php"
> [7]=>
> string(36) "/usr/local/php/lib/php/DB/common.php"
>
> Once again, the method not being found is DIRECTLY BELOW the method
> calling it in the source. Unless PHP is somehow not including *part* of
> a file, it's not a file inclusion problem.
>
> The error exists whether i use DB_common::quoteSmart() or
> DB_pgsql::quoteSmart(). My only recourse has been to modify the source
> to add escapeSimple()'s code inside quoteSmart().
>
> Here is the relevant (unedited) source from db_common.php:
>
> --- snip ---
> function quoteSmart($in)
> {
> if (is_int($in) || is_double($in)) {
> return $in;
> } elseif (is_bool($in)) {
> return $in ? 1 : 0;
> } elseif (is_null($in)) {
> return 'NULL';
> } else {
> return "'" . $this->escapeSimple($in) . "'";
> }
> }
>
> // }}}
> // {{{ escapeSimple()
>
> /**
> * Escapes a string according to the current DBMS's standards
> *
> * In SQLite, this makes things safe for inserts/updates, but may
> * cause problems when performing text comparisons against columns
> * containing binary data. See the
> * {@link http://php.net/sqlite_escape_string PHP manual}
> for more
> info.
> *
> * @param string $str the string to be escaped
> *
> * @return string the escaped string
> *
> * @see DB_common::quoteSmart()
> * @since Method available since Release 1.6.0
> */
> function escapeSimple($str)
> {
> return str_replace("'", "''", $str);
> }
> --- snip ---
>
> The error msg is "Fatal error: Call to undefined function:
> escapesimple() in /usr/local/php/lib/php/DB/common.php on line 434"
>
> Steps to reproduce:
>
> script has these includes:
> require_once "${_SERVER['DOCUMENT_ROOT']}/includes/php/get_dbi.php";
> require_once "${_SERVER['DOCUMENT_ROOT']}/includes/php/MyClass.php";
>
> get_dbi.php gets a DB connection and has:
> require('DB.php');
>
> inside MyClass:
> DB_common::quoteSmart($some_string);
>
> I get the same error if i add require_once('DB.php') to MyClass.
>
> Can anyone verify this or suggest why this could be happening?
>
Well no *wonder* it's happening. $this is used in quoteSmart(). It
*has* to be called on an instance. You can't call it statically.
$db = DB::connect($dsn);
$sql = 'SELECT * FROM table WHERE col='.$db->quoteSmart($value);
--
Justin Patrin