Skip to main content

Apache crashed while connecting to MYSQL

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.

Comments

Popular posts from this blog

Strange problem occured while trying to create a CSV file using PHP Script - The file is not seen on FTP but can download using file's absolute path url

Strange problem occured while trying to create a CSV file - The file is not seen on FTP but can download using file's absolute path url Last day I came across a strange problem when I tried to create a csv file on therver using a PHP script. the script was simply writing a given content as a csv file. The file will be created runtime. What happened was, The script executed fine, file handler for new file was created and contents was wrote into the file using fwrite and it returned the number of bytes that was written.

How to get the Query string of a URL using the Javascript (JS)?

JS function get the Query string of a URL or value of each parameter using the Javascript(JS)? If you want to get your current page's url var my_url=document.location; to get the query string part of the url use like this: var my_qry_str= location.search; this will return the part of the url starting from "?" following by query string Lets assume that your current page url is http://www.crozoom.com/2013/page.html?qry1=A&qry2=B then the location.search function will return " ?qry1=A&qry2=B " to exclue "?", do like this:


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 »
Member
Search This Blog