Home » Questions » Computers [ Ask a new question ]

Why does PHP throw "Segmentation fault (11)" after "mysql_connect", or upon "mysql_close"?

Why does PHP throw "Segmentation fault (11)" after "mysql_connect", or upon "mysql_close"?

I have Ubuntu-9.04 and am using XAMPP-1.7.2 to develop a web application. The problem is that when I try to view a PHP file I wrote by visiting localhost/folder/file.php, Firefox offers me to download it instead of showing me the file as a web page. If I do download it and open it in my favorite text editor, I get an empty file with nothing in it...

Asked by: Guest | Views: 191
Total answers/comments: 2
Guest [Entry]

"Smells like your mysql install. Is mysql running as a service? Does your root account really have no password? What mysql extensions are loaded in php.ini? There's a php_mssql.dll which can easily be mistaken for php_msql.dll, but I'm fairly certain the php_mssql.dll is for windows only.

Have you edited your php.ini /opt/lampp/php/php.ini?
These may help with debugging:

error_reporting = E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = On ;but you'll want to turn this off soon ;)
mysql.trace_mode = On

Also worth looking at, the port number used. Is $MYSQL_TCP_PORT set? How about the mysql-tcp entry in /etc/services?

Update:
Have you tried checking the return value of the connect function? I'm wondering if you example is too minimal. Try making your test look like this:

<?php

$db = mysql_connect(""localhost"",""root"",""myrootpassword"");
if (!$db) {
die('Could not connect: ' . mysql_error());
}
else {
$result = mysql_query(""show databases"");
print ""
<h1>Test executed from "". $_SERVER['SCRIPT_NAME']. ""</h1>

\n"";
print ""Script name: "". $_SERVER['SCRIPT_FILENAME'] ."" <hr>\n"";
while ($line = mysql_fetch_array($result))
{
print ""$line[0]<br>\n"";
}
}
mysql_close($db);

?>

This example ensure you send something back that looks like HTML whether your script fails or not. I was able to reproduce your symptoms with no root password set, so it's apparently not only good practice, but it's required to be non-empty.

I was able to turn your problem into a a solution by

Setting the root password
returning something from the script on connect

Instead of passing in """" as the root password, if it really is nothing, try using mysql.default_password as the password. The default value for mysql.default_password is NULL."
Guest [Entry]

"You say it's all up and running and that simple files are showing up okay. But then some files are prompting you to save the PHP file. This means you'll have to look at the code of those pages where it's breaking and asking you to save.

It's more than likely you have a line in the code that is killing the server or just making it give up parsing the PHP.

This could be a particular extension that's being used by that page or it could be another killbot function that hobbles the server into just sitting there with its arms crossed.

Your error logs show that the last thing to happen before it shoves the save dialog in your face is a connect to the database. Follow the code back to that and make sure that's solid before moving onto the next possible troubleshooting breadcrumb that may or may not arise.

Since you can see the file with no problem on another set up, in this case easyPHP, the problem is very much on the XAMPP set up and a configuration that is being tripped up by the code."