Forum Moderators: coopster
I have setup mySQL and PHP with apache2 on my home Windows XP computer.
When I have no password on my root <default user> the following test.php script will display the database. But if I have a password for my root it won't allow the test.php script to access the database in the c:/mysql/data folder.
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
printf("First Name: %s<br>\n", mysql_result($result,0,"first"));
printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));
printf("Address: %s<br>\n", mysql_result($result,0,"address"));
printf("Position: %s<br>\n", mysql_result($result,0,"position"));
?>
</body>
</html>
Every bit of documentation I read tells me I need a password for my root user. But if I have a password setup, testing with my database is not possible/accessible.
Does anyone know how I could approach this password/testing mysql database conflict?
This is the original error message:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'root@localhost' (Using password: NO) in C:\Program Files\Apache Group\Apache2\htdocs\testmydb.php on line 13
I tried the following you suggested:
$db = mysql_connect("localhost", "root", "password");
But when I did the above (with "password") it returned a different error:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'root@localhost' (Using password: YES) in C:\Program Files\Apache Group\Apache2\htdocs\testmydb.php on line 13
p.s. Was I supposed to replace password with my actual password? Or am I way off?
p.s. Was I supposed to replace password with my actual password? Or am I way off?
You are right on. The answer is Yes, replace it with your actual password.
The latter half of this thread addresses the question,
How would one best go about storing scripts off the document root? [webmasterworld.com]
(starting at the second question in msg #7) may help.
I read your suggested thread on storing scripts above the root folder. Currently, my htdocs folder is my document root. However, i still do not understand how to separate the scripts from the doc root and make it work.
I know I probably have to tell the scripts where to find the includes but then how is a test.php (with the password) still accessible at [localhost...] when it is moved above the doc root?
Perhaps I should start a new thread for this but:
1. Should the document root stay in the Apache2 folder?
2. How do I change the location of my php scripts (that include my root password, like my first post) above my doc root folder in the php.ini file?
; Windows: "\path1;\path2"
include_path = ".;c:\php5\includes"
Do I make any sense?
PHP include [php.net] function.
Example in msg #2 here [webmasterworld.com...]
>>1. Should the document root stay in the Apache2 folder?
The Document Root [httpd.apache.org] should be fine there, if you prefer. Did you read through the Apache Security Tips [httpd.apache.org]? You could also create a subdirectory (public, www, whatever...) in htdocs and make that your new Document Root, and put an "includes" directory in the htdocs directory. You may want to brush up Virtual Hosts [httpd.apache.org] if you intend to run more than one web site on a single machine.
>>2. How do I change the location of my php scripts (that include my root password, like my first post) above my doc root folder in the php.ini file?
That's right, modify the
include_pathconfiguration directive. You can specify a list of directories where the require(), include() and fopen_with_path() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in Unix or semicolon in Windows. See include_path [php.net] for more information.
Just to recap and bring closure to this thread.
This is what I did:
1. Created header.inc.php file
<?php
$db = mysql_connect("localhost", "root", "password_here");
mysql_select_db("submit_email",$db);
?>
<html>
<head>
<title>
<?php echo $title?>
</title>
2. Saved header.inc.php file to /includes (one level above the document root)
3. Created PHP page:
<title>Test</title>
<body>
<?php
include("header.inc.php");
?>
<td> </td>
<td><div align="center">
<h2>Body</h2>
</div></td>
<td> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td><div align="center">
<h3>Area</h3>
<p> </p>
<p><form action="thankyou.php" method="post" name="submit_email" id="submit_email">
<table width="100" border="0" cellspacing="0" cellpadding="10">
<tr>
<td><h3>Name:</h3></td>
<td>
<input name="name" type="text" id="name"></td>
</tr>
<tr>
<td><h3>Email:</h3></td>
<td>
<input name="email" type="text" id="email"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Enter Information"></td>
<td> </td>
</tr>
</table>
</form> </p>
</div></td>
<td> </td>
</tr>
</table></center>
<?php
include("footer.inc.php");
?>
4. Saved submit_email_body.php to document root.
5. Created footer.inc.php file
<div align="center">
<h3>FOOTER GOES HERE </h3>
</div>
</body>
</html>
6. Saved footer.inc.php to /inlcudes (one level above document root)
---------------------------
I hope this helps others...
Thanks Jatar and Coopster.
It gives me a warning in big red letters telling me.. 'Your configuration file contains settings (root with no password) that correspond to the default MySQL privileged account. Your MySQL server is running with this default, is open to intrusion, and you really should fix this security hole.'
I have entered the password in ebery config file everywhere I can think of, but obviously to no avail. I've been on this for 2 days and am going to cry soon!
Any ideas? Please?
Jim