Reputation: 4052
I'm a complete beginner at this, but I've set up an EC2 server and I'm trying to develop a simple php-mysql based website.
I've managed to get apache2 running and I've got a domain pointed to the server. I'm trying to set up a very simple php script to attach to a database. The following script runs perfectly well when I use the command line php simple_script.php
<?php
echo "Hello\n";
$con = mysql_connect("localhost","james","<password>");
if($con){
echo "Connected\n";
}
?>
However, when I go to www.myurl.com/simple_script.php
I only see the line "Hello". Any help would be gratefully received!
OK, so I've checked the apache error log, which is saying this:
PHP Fatal error: Call to undefined function mysql_connect() in /var/www/www.myurl.com/simple_script.php on line 5
Any ideas how to resolve this?
Upvotes: 2
Views: 2601
Reputation: 4352
You're using a deprecated function. Use mysqli_* or look into the PDO class. http://php.net has a great documentation on the language :)
Upvotes: 1
Reputation: 1465
If you're trying to figure things out (and if this isn't on a production server), I'd start by displaying php errors by enabling error reporting in your php.ini file. To find out where php.ini is located, create a file that uses the phpinfo() function, and you should get the path. (This will also show you if mysql is running.)
<?php phpinfo();?>
In php.ini, look for the "error_reporting" line and set it to something like:
error_reporting = E_ALL & ~E_NOTICE
Upvotes: 0