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?
Asked
Active
Viewed 128 times
-2
1 Answers
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
-
-
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
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