Home  »     »     »  Apache crashed while connecting to MYSQL

Apache crashed while connecting to MYSQL

Friday, May 28, 2010

I had installed latest WAMP and tried to load a php page which uses a class file.
the class file has code to connect to the Db for fetching records.
When ever the script attempts to make a connection i got the following Error
Window popup in IE and I am not able to do any DB related operation.

Code Sample
-----------------------------------------------------------------
function mysqlConnect(){
//Using Nonpersist connection
$this->_connection=@mysql_connect($this->str_dbServer, $this->str_dbUname, $this->str_dbPass) or $this->returnError("Unable to connect to Database server");
//Using Persist Connection

@mysql_select_db($this->str_dbName,$this->_connection); //Selecting DBASE
}



function mysqlDisconnect(){
// Disconnect the database after dbase access
@mysql_close();
}
----------------------------------------------------------------

How can this be solved?

This is the Err popup message that i got, after this message the browser hangs for few seconds.
----------------------------------------------------
Apache HTTP Server has encountered a problem and needs to close. We are sorry for the inconvenience.
If you were in the middle of something, the information you were working on might be lost.

Please tell Microsoft about this problem.

We have created an error report that you can send to us. We will treat this report as confidential and anonymous.

To see what data this error report contains, click here.
[Send Error Report] [Don't Send]
----------------------------------------------------


Fix to this Issue

This issue is related to the version of PHP. in php version greater that 5, to close a connection we need to specify the connection identifier as its param.

you MUST specify the connection handle.
mysql_close($conenction_handle);

So rewrite the code as

-----------------------------------------------------------------
function mysqlConnect(){
//Using Nonpersist connection
$this->_connection=@mysql_connect($this->str_dbServer, $this->str_dbUname, $this->str_dbPass) or $this->returnError("Unable to connect to Database server");
//Using Persist Connection

@mysql_select_db($this->str_dbName,$this->_connection); //Selecting DBASE
}



function mysqlDisconnect(){
// Disconnect the database after dbase access
@mysql_close($this->_connection);
}
----------------------------------------------------------------

This will work.



How to link to this page?
If you wish to link to this page from your website, simply Copy and paste the above HTML code to your web page. It will appear on your page as:
Apache crashed while connecting to MYSQL.




Share this!




comments powered by Disqus

This Weeks 7 Popular Posts


Subscribe to Recent Posts by Email
Stay connected to CROZOOM with regular Email notices of new Techie articles and IT Jobs. Updates will be delivered to your Inbox as soon as they are posted online.

Enter Your Email Address:  

Delivered by FeedBurner   RSS Feed

Search this Blog   



Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »