Call to undefined function mysql_escape_string()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sysop1911
Forum Newbie
Posts: 10
Joined: Fri Aug 28, 2009 1:54 pm

Call to undefined function mysql_escape_string()

Post by sysop1911 »

Anyone know why I would get this error when I go to http://localhost? I'm running Apache/PHP/MySQL on a Windows Server 2003 R2 box. I upgraded Apache and that works fine, but now I get this error message. I already checked the php.ini file and the php_mysql.dll extension is loaded.

PHP version is 5.2.6
MySQL version is 5.0.51b
Apache was just upgraded from 2.2.9 to 2.2.13
We use a CMS called 'ez publish'.
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Call to undefined function mysql_escape_string()

Post by AlanG »

mysql_escape_string

"This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged." - PHP.net
(I realise your PHP version is below PHP 5.3.0 but try the new one anyway. If the extension is there and everything is working properly, it should be working.)

Use this one:
mysql_real_escape_string

Note: you should look into the MySQL Improved extension (mysqli)
sysop1911
Forum Newbie
Posts: 10
Joined: Fri Aug 28, 2009 1:54 pm

Re: Call to undefined function mysql_escape_string()

Post by sysop1911 »

The problem is, in the code it's an if/else statement that has both the "mysql_real_escape_string" and the "mysql_escape_string". Here is the code:

--------------------------------------------------------------------------------------
function escapeString( $str )
{
if ( $this->IsConnected )
{
return mysql_real_escape_string( $str, $this->DBConnection );
}
else
{
return mysql_escape_string( $str );
}
}
---------------------------------------------------------------------------------------

So I don't think I can use the mysql_real_escape_string twice. I'm thinking maybe it has something to do with some of the dlls that were loaded in the new version of apache that got rid of the use of "mysql_escape_string". Any ideas?
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Call to undefined function mysql_escape_string()

Post by AlanG »

You can use functions as many times as you want. The code inside a conditional block isn't even considered for execution unless the condition is valid. It must be a back end problem. Try downloading the php_mysql.dll again and overwriting the file in your extensions folder. If that doesn't work, try reinstalling PHP. There may have been some problem the first time.
sysop1911
Forum Newbie
Posts: 10
Joined: Fri Aug 28, 2009 1:54 pm

Re: Call to undefined function mysql_escape_string()

Post by sysop1911 »

AlanG wrote:You can use functions as many times as you want. The code inside a conditional block isn't even considered for execution unless the condition is valid. It must be a back end problem. Try downloading the php_mysql.dll again and overwriting the file in your extensions folder. If that doesn't work, try reinstalling PHP. There may have been some problem the first time.
I know a function can be used more than once, but if it's an if/else statement, you'd think that the 'if' and 'else' parts should be different. If I use mysql_real_escape_string twice, the conditions would the same, and thus no point of the if/else statement. I'm wondering why simply upgrading Apache caused this. I didn't touch the PHP or MySQL installs. I'll download the php_mysql.dll and see if that helps. Thanks for your help.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Call to undefined function mysql_escape_string()

Post by John Cartwright »

By default, the mysql extension is not enabled. In your php.ini, locate a line similar to

Code: Select all

;extension=php_mysql.dll
and remove the semi colon. Afterwards, restart apache/IIS and you should have access to the extension.
sysop1911
Forum Newbie
Posts: 10
Joined: Fri Aug 28, 2009 1:54 pm

Re: Call to undefined function mysql_escape_string()

Post by sysop1911 »

John Cartwright wrote:By default, the mysql extension is not enabled. In your php.ini, locate a line similar to

Code: Select all

;extension=php_mysql.dll
and remove the semi colon. Afterwards, restart apache/IIS and you should have access to the extension.
I already checked this and the php_mysql.dll extension is loaded. There is no semi-colon there. Can you tell me a way to edit the code in my third post to use mysql_real_escape_string instead of mysql_escape_string? Mysql_real_escape_string takes two arguments and the mysql_escape_string takes only one.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Call to undefined function mysql_escape_string()

Post by John Cartwright »

//guilty of post skimming

Try running phpinfo() in a test file to make sure you are modifying the correct php.ini (as there may be several on your system). Otherwise, I would suggest checking the apache error logs to see if the module is failing to load and why.
sysop1911
Forum Newbie
Posts: 10
Joined: Fri Aug 28, 2009 1:54 pm

Re: Call to undefined function mysql_escape_string()

Post by sysop1911 »

I checked the only php.ini on the machine and php_mysql.dll is listed w/o semicolon. Not sure why that would have changed in an Apache upgrade, anyhow. Also, I ran "php -m" from the command prompt and mysql is listed twice.

Does the fact that I got this error indicate to you that the mysql extension isn't loaded?

Thanks.
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Call to undefined function mysql_escape_string()

Post by AlanG »

sysop1911 wrote:Also, I ran "php -m" from the command prompt and mysql is listed twice.
Is mysql listed twice or is the second extension mysqli? They are two different extensions

Update:

I tracked this down, maybe it will help.
External Resource wrote:In php 5, MySQL is no longer enabled by default, nor is the MySQL library bundled with php. Read this FAQ for details on why. Because of this, Windows users will need to enable php_mysql.dll inside of php.ini and either copy libmysql.dll into the Windows system directory or make it available to the PATH. For compiling, simply use --with-mysql=[DIR] where [DIR] points to your MySQL installation directory.
sysop1911
Forum Newbie
Posts: 10
Joined: Fri Aug 28, 2009 1:54 pm

Re: Call to undefined function mysql_escape_string()

Post by sysop1911 »

AlanG wrote:
sysop1911 wrote:Also, I ran "php -m" from the command prompt and mysql is listed twice.
Is mysql listed twice or is the second extension mysqli? They are two different extensions

Update:

I tracked this down, maybe it will help.
External Resource wrote:In php 5, MySQL is no longer enabled by default, nor is the MySQL library bundled with php. Read this FAQ for details on why. Because of this, Windows users will need to enable php_mysql.dll inside of php.ini and either copy libmysql.dll into the Windows system directory or make it available to the PATH. For compiling, simply use --with-mysql=[DIR] where [DIR] points to your MySQL installation directory.
With the php -m command, 'mysql' is definitely listed twice.

Regarding php 5, I was already running php 5.2.6 before I tried to upgrade apache and everything worked fine, so unless the apache upgrade somehow disabled php or the mysql extension in php, I'm not sure why your quote would apply to my situation. I appreciate the help, though.

I'm thinking that maybe one of the dlls in the apache\bin folder changed something in Php. There is one called "apr_dbd_mysql-1.dll" and a bunch of php dlls.
sysop1911
Forum Newbie
Posts: 10
Joined: Fri Aug 28, 2009 1:54 pm

Re: Call to undefined function mysql_escape_string()

Post by sysop1911 »

An update: I changed the "Mysql_escape_string" line to "mysql_real_escape_string(blah, blah)" and I got the same error as before except this time it read:

Call to undefined function mysql_real_escape_string() in C:\blah\blah.php

So it looks like it's definitely php or mysql not loading just like you guys said.
Post Reply