-2

I'm a little very very new to php so I don't know what to do , I just finished the setup of mysql and I can go in the mysql console and ... , The only thing I'm stuck is that how can I make my php file connect to the mysql (The Php is in the wwwroot in windows(localhost)) or how can I install the mysql on wwwroot?

Kshahnazari
  • 115
  • 6
  • 4
    Maybe you can google: "php connect to mysql" ? – Royal Bg Sep 12 '13 at 19:52
  • You don't install mysql into wwwroot - you "connect" to mysql with PHP – user20232359723568423357842364 Sep 12 '13 at 19:52
  • MySQL is a service on your server that other applications/users can connect to. Look into a tutorial that steps you through setting up WAMP (Windows/Apache/MySQL/PHP) or simply google using functions like mysqli_connect() and troubleshoot from there... There are some configurations in php.ini that you'd need to make that tutorials would step you through. – Grambot Sep 12 '13 at 19:54
  • Error connecting to database: " . mysql_error() . ""); echo "

    Connected to MySQL!

    "; ?> When I run it it says unknown function mysql_connect so actually its not knowing mysql
    – Kshahnazari Sep 12 '13 at 20:22

1 Answers1

1

I presume you are using Wamp..

Go to phpMyAdmin create a DB first and add some tables as per your need.

Then create a config.php file with some code as below:

<?php 

$connection = mysql_connect("localhost","root","");
if(!$connection){echo mysql_error(); die(0);}
mysql_select_db("databasename",$connection);

?>

Here root is the name of user and password is left blank as in general scenario for your local server. put the name of the database you created in place of "databasename".

and include this config.php file to every page where you need to access your database.

jGupta
  • 2,243
  • 4
  • 22
  • 49
  • It will work, but this practice has been left in the past century. – Royal Bg Sep 12 '13 at 20:13
  • As long as its helping someone who just needs some push to get along with PHP.. I don't mind. And codes apart, i'm only 256 years old :-p – jGupta Sep 12 '13 at 20:15
  • I hope I'm misunderstanding your wording, and you aren't suggesting leaving a blank database password... – Andrew Barber Sep 13 '13 at 05:17
  • yes.. what harm does it cause if u r setting a local database connection. just to get started with PHP. – jGupta Sep 13 '13 at 05:20