Call to undefined function mysql_escape_string()
Moderator: General Moderators
Call to undefined function mysql_escape_string()
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'.
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'.
Re: Call to undefined function mysql_escape_string()
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)
"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)
Re: Call to undefined function mysql_escape_string()
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?
--------------------------------------------------------------------------------------
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?
Re: Call to undefined function mysql_escape_string()
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.
Re: Call to undefined function mysql_escape_string()
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.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.
- 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()
By default, the mysql extension is not enabled. In your php.ini, locate a line similar to and remove the semi colon. Afterwards, restart apache/IIS and you should have access to the extension.
Code: Select all
;extension=php_mysql.dllRe: Call to undefined function mysql_escape_string()
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.John Cartwright wrote:By default, the mysql extension is not enabled. In your php.ini, locate a line similar toand remove the semi colon. Afterwards, restart apache/IIS and you should have access to the extension.Code: Select all
;extension=php_mysql.dll
- 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()
//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.
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.
Re: Call to undefined function mysql_escape_string()
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.
Does the fact that I got this error indicate to you that the mysql extension isn't loaded?
Thanks.
Re: Call to undefined function mysql_escape_string()
Is mysql listed twice or is the second extension mysqli? They are two different extensionssysop1911 wrote:Also, I ran "php -m" from the command prompt and mysql is listed twice.
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.
Re: Call to undefined function mysql_escape_string()
With the php -m command, 'mysql' is definitely listed twice.AlanG wrote:Is mysql listed twice or is the second extension mysqli? They are two different extensionssysop1911 wrote:Also, I ran "php -m" from the command prompt and mysql is listed twice.
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.
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.
Re: Call to undefined function mysql_escape_string()
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.
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.