Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I' have created a database on the MySQL on my server. I need to connect to this via my website using PHP. This is the data of my connections file:

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass)
    or die('Error connecting to mysql');

$dbname = 'epub';
mysql_select_db($dbname);

I know what is the username and passwords are, and I know the IP address of the server also. What I'm simply wondering is how do I know which port I should use?

1 Answer

0 votes
by (12.7k points)
edited by

If your MySQL server runs on default settings, you don't have to specify that.

The default MySQL port is 3306.

[updated to show mysql_error() usage]

$conn = mysql_connect($dbhost, $dbuser, $dbpass)
    or die('Error connecting to mysql: '.mysql_error());

Join the SQL Course by Intellipaat fast, to Learn SQL concepts in detail and get certified.

Related questions

0 votes
1 answer
asked Dec 31, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jan 7, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jan 3, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jan 1, 2021 in SQL by Appu (6.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...