Jump to content

Archived

This topic is now archived and is closed to further replies.

jagguy

can't access mysql with php setup

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.