Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to php/mysql and i want to simply connect to my database. When i run the code below on my server i get a http 500 error. I am hosting it on a Ubuntu server machine (not a virtual machine) with port 80 open. of course php and mysql server are installed.

What I have tried:

<?php
	$servername = "localhost";
	$username = "root";
	$password = "*******";


    mysql_connect($servername,$username,$password);
	echo "hi";
?>
Posted
Updated 1-Oct-18 7:31am

See PHP: mysql_connect - Manual[^]. Port 80 is HTTP, MySQL uses port 3306 by default.
 
Share this answer
 
Comments
Member 13915301 1-Oct-18 12:22pm    
i have also forwarded 3337 (for mysql)
Richard Deeming 3-Oct-18 13:12pm    
That sounds like a really bad idea. Do you really want every hacker on the planet trying to guess your MySQL root password?

The only thing that needs to talk to MySQL is the code running on the server. If the PHP code is running on the same computer as MySQL, there should be no need to open the MySQL port at all.
Member 13915301 3-Oct-18 16:54pm    
ok i closed the port, do you know why my code doesn't work?
Richard MacCutchan 4-Oct-18 4:07am    
Sorry no, how could I with so little information? You need to do some debugging to find out what is happening in your server code.
use
mysqli_connect(host,username,password,db) 
instead of mysql_connect
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900