Jump to content


Photo

can't access mysql with php setup


  • Please log in to reply
3 replies to this topic

#1 jagguy

jagguy
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 18 September 2006 - 11:18 AM

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 5

Warning: 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 9

Warning: 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?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 September 2006 - 02:08 PM

Try this instead:
$conn = mysql_connect($dbhost, 'root', '');

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.

#3 jagguy

jagguy
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 19 September 2006 - 12:13 AM

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 ?

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 10:38 AM

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:
$conn = mysql_connect('localhost:3363', 'root', '') or die('Unable to connect to MySQL:<br />' . mysql_error());
The number after 'localhost:' is the port number in which the mysql server is running on.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users