FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


The last foolish PHP/MySQL Question of the Year....





rameshbn1
Hello People.

I sneaked a XXAMP installation onto one of the LAN computers in my office. Then I did the following things over a week:
    Figured out that the Apache Server should be running to run PHP script
    Figured out that php files should be saved into the 'htdocs' folder for the scripts to work
    Figured out what the 'localhost' things is
    Wrote a few silly scripts to satisfy my ego.

Now that I did all these things, I'm, to my great dismay, getting ambitious. I'd like to know:
    How do I configure my present computer as the server to work over LAN? How can I access the php scripts that I wrote here from another computer on the LAN?
    Will someone teach me the secrets behind connecting to a MySQL database from my php scripts? I cant' figure this out though I know a bit of SQL.

You should have figured out the level of my geekiness by now Razz
TomS
If your computers are connected via normal switch, just type the computersname of your server (you get it by typing 'hostname' in the commandline CMD) into the adressbar of the browser on your second/third and so on pc. for example: 'http://firstcomputer/'

If you are connected with a router, because you want to access the internet from each of the computers, you have to setup portforwarding. Look into the user's manual how to do that.

For the MySQL thing I'm not an expert. And got to look myself on several manuals, each time I want to do something with databases. I guess there are people that are more competent in such things.
hexkid
rameshbn1 wrote:
Will someone teach me the secrets behind connecting to a MySQL database from my php scripts?

First thing is to enable MySQL in your installation.
For that you'll need to edit php.ini: remove the semicolon from the start of the mysql line
Code:
...
extension=php_mysql.dll
...

Don't forget to restart Apache after every change to php.ini.

You can check if MySQL is enabled in your installation from phpinfo(). Try this script and examine its output
Code:
<?php
phpinfo();
?>
ncwdavid
you can connect to mysql in a php script by doing this:
Code:

$connect = mysql_connect("localhost","db_username","db_password");
if(!$connect){
echo "There was a problem connecting to the database".mysql_error();
}

Then to select the database:
Code:

$select_db = mysql_select_db("database_name", $connect);
Diablosblizz
Code:
$connect = mysql_connect("localhost","db_username","db_password");


Don't you have to use the networks IP if the host is not on your home computer? Localhost is on the local machine. So you would change it to something like:

Code:
$connect = mysql_connect("24.586.4967","db_username","db_password");


24.586.4967 is an example IP.
TomS
1st. He installed XAMPP so he IS working on localhost.
2nd. You only need this, if you connect to another server. eg if MySQL is on another computer installed than apache. This is not the case on frihost. So localhost is correct. If any hoster has a different server for SQL, he will tell you, that you have to write eg sql.hostername.com instead of localhost.
Diablosblizz
Im not a complete moron.

Sorry, I wasn't reading his post correctly, I thought he wanted to access his server off of another connection. Anyways yes Localhost would work.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.