Page 1 of 1

please help noob i dont know how to connect mysql to php

PostPosted: 09. May 2010 02:38
by hi5
i have download xampp and i dont know how to connect mysql to php. i dont know were to save the file that i have create.
so i have been reading some tutorial about conecting my mysql to php and iam not sure were to put these file.
So, my question is is the code right and were do i save this files. :| :cry:

i have create 3 files.

1st file named connection.php

Code: Select all
<?php
$dbhost = 'localhost';
$db      = 'info';
$dbuser = 'root';
$dbpass = 'trun';                         // password not real  so people cant hack it

}

?>


second file name is index.php
i dont know were to save this file
Code: Select all
<?php

   include ('connection.php');
   
   $connect = mysql_connect($dbhost, $db_user, $db_pass);
if(!connect){

   die ( "could not coect tothe database: <br />". mysql_error());
}

?>



3rd file data.php
i dont know were to save this file
Code: Select all

$db_select=mysql_select_db($info);
if(!$db_select)
{
   die ("could not select the database: <br />". mysql_error());
}

Re: please help noob i dont know how to connect mysql to php

PostPosted: 09. May 2010 02:49
by JonB
If you install XAMPP, "it" will make all the connections for you.

That will install Apache, MySQL, PHP, Perl and FileZilla FTP server.

So - Install XAMPP, and then use the Control Panel to start Apache and MySQL.

then look at the tutorials about XAMPP on this page
http://www.apachefriends.org/en/xampp-windows.html

Good Luck
:roll:

Re: please help noob i dont know how to connect mysql to php

PostPosted: 09. May 2010 02:51
by hi5
so do i need all those code?? because i want to be able to create a database driving web site

Re: please help noob i dont know how to connect mysql to php

PostPosted: 09. May 2010 02:53
by JonB
No - you don't need that code you wrote. All the hard wiork has been done

read the tutorials

Re: please help noob i dont know how to connect mysql to php

PostPosted: 09. May 2010 02:56
by hi5
yea i cant find the tutorials all i find is a bunch of question

Re: please help noob i dont know how to connect mysql to php

PostPosted: 09. May 2010 03:09
by JonB
XAMPP is really an installer for a group of programs. Apache PHP, Perl MySQL and so on.

So the tutorials are about running XAMPP. To learn how to develop a database driven site is not the purpose of those tutorials. They are there to make XAMPP work.

In your browser type in: http://localhost

you should find that XAMPP is installed. There is a huge amount of info about how all the parts are configured when you launch XAMPP on your machine.

THEN you will be ready to start trying to apply knowledge gained from subject speicific tutorials to build a web site.

:roll:

Re: please help noob i dont know how to connect mysql to php

PostPosted: 09. May 2010 03:10
by hi5
thank, for your help

Re: please help noob i dont know how to connect mysql to php

PostPosted: 24. May 2010 03:31
by MC10
By the way, $db_user and $db_pass in index.php are undefined, as they are $dbuser and $dbpass in your connection.php.