Domanda

I posted another question that is similar to this but I believe this to be a separate issue. Accessing MySql Database from PHP file on local host

While trying to execute the following line

$db = mysql_connect('ipaddress','username','password!!') or die("Connection error");

On my local raspberry pi lamp web server I get a internal 500 server error. It doesn't matter if I try and connect to an external Database or the local one that I want. I get the same internal 500 error response.

update:

After checking the error.log file it appears this is the reported error

"Call to undefined function mysql_connect() in [path]"

È stato utile?

Soluzione

You haven't installed mysql for php, or php can't find the installation. Make a phpinfo() site and look there for mysql. If it isn't there try executing apt-get install php5-mysql

Altri suggerimenti

mysql_connect is deprecated and will soon be removed from the PHP trunk, if this is a very new installation of PHP or MySQL that might be the problem, new development really should be done with MySQLi or PDO library

this is how you do it in MySQLi (object orientated)

$mysqli = new MySQLi($db_server, $db_username, $db_password, $db_database);

(procedural)

$mysqli = mysqli_connect("example.com", "user", "password", "database");

Also make sure the DB user has permission to access the databases in question, if your accessing a remote database you also have to add the source to the approved list for the mySQL server (either domain or IP address).

500 errors are hard to diagnose, 500 simply means the server didn't understand, or couldn't process the request (Its the error that occurs when other errors don't apply)the good news is the server is actually receiving the request.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top