jagguy Posted September 18, 2006 Share Posted September 18, 2006 I have latest stable release of php,apache,mysql but I can't conncect between mysql with php on apache.I can create a database and tables with command prompt in mysql. On the php info script test mysql appears. I try to access a database with php from mysql. <?php$dbhost = 'localhost';$conn = mysql_connect($dbhost);$dbname = 'petstore';mysql_select_db($dbname);?> The errors I get is Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\Apache Group\Apache2\htdocs\myone2.php on line 5Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\Apache Group\Apache2\htdocs\myone2.php on line 9Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\Program Files\Apache Group\Apache2\htdocs\myone2.php on line 9Is my setup wrong? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 18, 2006 Share Posted September 18, 2006 Try this instead:[code=php:0]$conn = mysql_connect($dbhost, 'root', '');[/code]You need to define the username you want to use to connect to the MySQL server. the third paramter is where you enter the password in for the username you use. Quote Link to comment Share on other sites More sharing options...
jagguy Posted September 19, 2006 Author Share Posted September 19, 2006 q) I don't have a username or password setup and I don't want one either. Where do I effect the username/password?q)When I do the server instance wizard (mysql)the security part fails on me as it claims port 3363 on is not open and to check the firewall, does this effect php ? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 19, 2006 Share Posted September 19, 2006 By defualt MySQL should have set up a username which is root (which has no password set) during setup. You must have at least one user setup to access the MySQL database, this user will be the admin of the MySQL server.For your secound question yes. You'll want to open port 3363 in order for queries to be set to the database. Without the port being open PHP will not be able to send any requests to and from the MySQL database.Also as you are using a port that is not the defualt (3306) you'll need to tell PHP which port your MySQL server is running on. So you'll want to do something like this:[code=php:0]$conn = mysql_connect('localhost:3363', 'root', '') or die('Unable to connect to MySQL:<br />' . mysql_error());[/code]The number after 'localhost:' is the port number in which the mysql server is running on. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.