Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there guys

I am quite new to php stuff so please help me out.

I have a simple question on connectivity to the server. I need to connect to my school's server from my home laptop, i have the UN, Password for the Mysql db that i need to use in that server. How can I connect to that server from my PHP script, say the server address is a.b.mmit.edu , something like that. I know I can't use localhost because it means i am using my local database, but to use the school's db what should i do to connect using php.

is this how to do it??
PHP
$connection = mysql_connect("a.b.mitt.edu","user",'pass');
Posted
Updated 30-Oct-12 16:35pm
v2

1 solution

Before attempting to access that database from your script, first ensure that the database is accessible from the server at which your PHP Engine is located. Some servers have restrictions to the IP Addresses that may access the specific server for security purposes.
PHP
<?php
//This will connect you to the server, and if it fails, you will get the error message telling you why
$connection = mysql_connect("host_name", "username", "password") or die("MySQL Error: ".mysql_error());

//This will connect you to the selected database and if it fails, you will get an error message giving you the reason
$database = mysql_select_db("database_name") or die("MySQL Error: ".mysql_error());
?>

Please note that if no Error message is returned, you have access to the database and the server. But if a message is returned with the error above, the error message will help you determine the cause.

Happy to help. Wish you all the best.
 
Share this answer
 
v2

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