Jump to content

Recommended Posts

my code work fine, until i add mysql_real_escape_string() for my user inputs and get all the warning like this:

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'apache'@'localhost' (using password: NO) in /home/mysite/domains/mysite.com/public_html/phpm/mypage.php on line 157

 

line 157 is the line that i add mysql_real_escape_string() for my user input...

 

so, what error i have made here?

Link to comment
https://forums.phpfreaks.com/topic/168122-mysql_real_escape_string/
Share on other sites

mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. Although depreciated, mysql_escape_string doesn't need a connection. You must connect to your mysql before using thisl

 

ya, thanks. the problem is solved now...

as a newbie, i would like to know can i just put the mysql connection code at the top of each php file regardless it's needed or not, to avoid the same problem happen again? and need i to explicitly close the connection each time it's used?

mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. Although depreciated, mysql_escape_string doesn't need a connection. You must connect to your mysql before using thisl

 

ya, thanks. the problem is solved now...

as a newbie, i would like to know can i just put the mysql connection code at the top of each php file regardless it's needed or not, to avoid the same problem happen again? and need i to explicitly close the connection each time it's used?

 

There is no implementation to PHP to make that happen automatically. It needs a connection handler, meaning its required everytime you use it in a php script.

 

To free more memory you can close the connection. I believe making a file called "dbconnection.php" and placing it in your include folders or wherever you like is helpful.

 

on top of every page just put

 

include("dbconnection.php");

 

There is no implementation to PHP to make that happen automatically. It needs a connection handler, meaning its required everytime you use it in a php script.

 

what do you meant in this case, please? mysql_real_escape_string()?

 

To free more memory you can close the connection. I believe making a file called "dbconnection.php" and placing it in your include folders or wherever you like is helpful.

 

on top of every page just put

 

include("dbconnection.php");

 

ya, currently i did do like what exactly you have suggested here. but, i didn't have any code to close the connection...so, seem that i kept include the dbconnection.php in each of my php file...will this causing any problem, when many visitors visit my site and open every page again and again, making the connection kept established?

There is no implementation to PHP to make that happen automatically. It needs a connection handler, meaning its required everytime you use it in a php script.

 

what do you meant in this case, please? mysql_real_escape_string()?

 

To free more memory you can close the connection. I believe making a file called "dbconnection.php" and placing it in your include folders or wherever you like is helpful.

 

on top of every page just put

 

include("dbconnection.php");

 

ya, currently i did do like what exactly you have suggested here. but, i didn't have any code to close the connection...so, seem that i kept include the dbconnection.php in each of my php file...will this causing any problem, when many visitors visit my site and open every page again and again, making the connection kept established?

 

If you want to close it during the script.... then use mysql_close. Otherwise non-persistent open links are automatically closed at the end of the script's execution.

 

The mysql_connect is a resource, you wont overwrite the last connection, it doesnt RE-establish, it only does it once during the script everytime its loaded.

 

no need to worry.

There is no implementation to PHP to make that happen automatically. It needs a connection handler, meaning its required everytime you use it in a php script.

 

what do you meant in this case, please? mysql_real_escape_string()?

 

To free more memory you can close the connection. I believe making a file called "dbconnection.php" and placing it in your include folders or wherever you like is helpful.

 

on top of every page just put

 

include("dbconnection.php");

 

ya, currently i did do like what exactly you have suggested here. but, i didn't have any code to close the connection...so, seem that i kept include the dbconnection.php in each of my php file...will this causing any problem, when many visitors visit my site and open every page again and again, making the connection kept established?

 

If you want to close it during the script.... then use mysql_close. Otherwise non-persistent open links are automatically closed at the end of the script's execution.

 

The mysql_connect is a resource, you wont overwrite the last connection, it doesnt RE-establish, it only does it once during the script everytime its loaded.

 

no need to worry.

 

then, will it causing many connections being open due to increase of visitors, and at the end causing memory leak?

There is no implementation to PHP to make that happen automatically. It needs a connection handler, meaning its required everytime you use it in a php script.

 

what do you meant in this case, please? mysql_real_escape_string()?

 

To free more memory you can close the connection. I believe making a file called "dbconnection.php" and placing it in your include folders or wherever you like is helpful.

 

on top of every page just put

 

include("dbconnection.php");

 

ya, currently i did do like what exactly you have suggested here. but, i didn't have any code to close the connection...so, seem that i kept include the dbconnection.php in each of my php file...will this causing any problem, when many visitors visit my site and open every page again and again, making the connection kept established?

 

If you want to close it during the script.... then use mysql_close. Otherwise non-persistent open links are automatically closed at the end of the script's execution.

 

The mysql_connect is a resource, you wont overwrite the last connection, it doesnt RE-establish, it only does it once during the script everytime its loaded.

 

no need to worry.

 

then, will it causing many connections being open due to increase of visitors, and at the end causing memory leak?

 

like i said it closes itself at the end of the script, ALL OF THE CONNECTIONS WILL CLOSE! If theres any reason you want to speed up the script then close it right after your done with the connection.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.