php5 and mysql5 on windows server - php

I have installed php5 and mysql5 on my server , I can login to mysql from command,
but when I try to connect using php I got this error message:
Access denied for user 'root'#'localhost' (using password: YES)PHP Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'#'localhost' (using password: NO) in D:\HostingSpaces\law-training\lawtraining.ir\wwwroot\includes\class.php on line 279 PHP Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in
I dont use 'ODBC'#'localhost' in my code at all.
I check using phpmyadmin , also I can't use it and can't connect to server.I use port 3309 for mysql , and from local or remote php can't login.
I use also mysql4 on this server on port 3306 and I can use it without problem.
how can i fix this problem?
Thanks

Try logging in to localhost:3309, I think you'll find that you're running it on a non-standard port, so you need to tell PHP where to look for the server.
ie.
mysql_connect("localhost:3309", "root", "mypassword");
As a sidenote, the ODBC#localhost connection is what mysql_query tries to use if there's no connection already open.

Is this a brand new MySQL 5 installation, and you have no means to log into it? You may want to reset the root password.
http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html
That should enable you to access MySQL using the command line. Then, make sure you have a root#localhost user and grant the relevant permissions to that user. For example:
mysql> GRANT ALL PRIVILEGES ON . TO 'root'#'localhost'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
If the problem persists with odbc connections, make sure your odbc data access product is fully compatible with your version of MySQL 5.x
Regards,
Netrista Khatam
Technical Services Manager
OpenLink Product Support

Related

Error while connecting a server database from local host

I want to run PHP script in local system (localhost) and the data to be stored in the server database. I'm getting an error while connecting to remote mysql database from localhost through PHP script.
Warning: mysql_connect(): Access denied for user 'XXXX'#'ip address' (using password: YES) in E:\xampp\htdocs\New\example\include\config.php on line 13
I tried using
$con= mysql_connect("example.com:3306","db username","password");
mysql_select_db('db', $con);
I tried using mysqli_connect(...) also but I couldn't connet.
somebody please guide me how can I resolve this?
If you are running it on Localhost then do it like this
$connection = mysqli_connect('localhost','username', 'password', 'database');
When you use mysqli you don't need to use the mysql_select_db as this information is passed in when you create the connection.
The main fix that I will stress here is using your first credential passed into the connect variable as 'Localhost' if its local on your machine and you are using xampp or mamp etc then use localhost.
this syntax that you have done mysql_select_db('db', '$con') is wrong when using mysql you DO NOT need to pass a $connection variable into mysql as this only applies for the new mysqli.
Last word of advice as soon as your comfortable (preferably asap) move away from mysql functions and use mysqli, the move is not too different you just have to learn where to pass in the $conn variables.
Seams like you have not granted privileges to user.
Try this on your remote database.
~$ mysql -u root -p
Enter Password:
mysql> grant all privileges on *.* to user identified by 'pass' with grant option;
Oh, check out Kenziiee Flavius answer first - that might already solve your problem as you are on localhost.
Log in to your Server via commandline:
mysql -u username -p
Create a new user for your remote host:
CREATE USER 'username'#'192.168.0.1' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'192.168.0.1';
Replace 192.168.0.1 with the ip or hostname of your remote host.

Error while connecting to mysql database from php

I have recently started exploring free hosting sites where they provide free mysql and php.
I have created a database and trying to connect to the database from php script. But while running the php. I am getting following error :
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a1696486_test '#'localhost' (using password: YES) in /home/a1696486/public_html/myphp/test1.php on line 2
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'a1696486'#'localhost' (using password: NO) in /home/a1696486/public_html/myphp/test1.php on line 3
Any idea whats the problem ?
Regards,
Shankar
I have this issue on our dedicated servers, and the solution for me is to provide the fully qualified domain name rather than 'localhost'. For exmaple, my connection is:
mysqli_connect('dedi81.jnb1.host-h.net', 'user', 'pass', 'db');
Where even though localhost is the same as dedi81.jnb1.host-h.net (MySQL server and web server on one machine) I - for some reason - cannot use 'localhost'.
Another issue may be that on the hosting company you're with, they have not granted to you the correct permissions, or that there is indeed an error with the username and / or password.
You can also try and substitute 'localhost' with the IP address of the MySQL machine.
Kind regards,
Simon

I'm trying to connect to a mysql database using PHP but it won't work

I've Installed mysql, php, apache using a wamp configuration
Where to access localhost is would be http://localhost:81
the PHP script I'm using is
if(mysql_connect('localhost', 'root', 'exobytes15')) {
mysql_select_db('testDB');
}
else {
echo 'Could not Connect to the database';
}
But this gives me the error
1045: Access denied for user 'root'#'localhost' (using password: YES)
What should I do to fix this problem?
Either you didn't grant root#localhost the necessary rights to access the database or you're providing the wrong password.
Note : granting access to root#`%` does NOT grant access to root#localhost...
Make sure you have that your database is running, and that the user has access to it.
You can use either use the plain old mysql commandline client for this or phpmyadmin if your wamp stack has that installed.
You're connecting with the wrong password: Reset the password
or more likely: you don't have privileges to connect from localhost.
Run the command:
GRANT ALL PRIVILEGES ON *.* TO 'root'#localhost WITH GRANT OPTION;
Test to see if you can connect.
Never do: GRANT ALL PRIVILEGES ON *.* TO 'root'#% WITH GRANT OPTION;
Because that will put your database server at risk from remote login attempts.
Maybe u are running mysql on a port other than the default port.
If it is the case use this:
mysql_connect('localhost:PORT', 'root', 'exobytes15')

File Doesn't Work in Virtual Server

I have a PHP file called footer10.php that worked just fine in shared hosting. I moved it to a virtual server and it no longer works.
I get these errors when I pull the file up in a browser:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'apache'#'localhost' (using password: NO) in /var/www/.../...com/httpdocs/.../footer10.php on line 23
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/.../...com/httpdocs/.../footer10.php on line 23
Access denied for user 'apache'#'localhost' (using password: NO)
This is on line 23 of the file:
$presult = mysql_query("SELECT COUNT(*) FROM submission") or die(mysql_error());
Any idea what I need to do to make the file work on the virtual server?
Thanks in advance,
John
The error message means that PHP could not connect to the MySQL database.
If you're establishing the connection on your own using mysql_connect you should make sure that host, user and password are correct (according to the error message no password was specified)
The user name and the empty password makes me think you've relied on the mysql.default_* settings on your old server. You can specify a default server in your php.ini, refer to the manual for this. The connection will then be opened automatically by php.
So what you have to do is to find out correct credentials for your MySQL server. Then you either establish a connection using mysql_connect/mysql_pconnect or add it to the php.ini.
Access denied for user 'apache'#'localhost' (using password: NO) , what does this line mean ?
It means you need to update you're mysql connection settings with the correct ones ( username , password and host ) by this i mean you're mysql connection settings on the new server are different than the ones on the old server . Then make shure to move the database from one server to another .

Why do I get "Access denied for user 'root'#'myhostname" when connecting to my database in PHP?

I have set up an Apache server on mandriva linux 2010.1. But the problem is whenever I'm trying to connect with the database, it's giving me the following error:
Error:Database error: SQLSTATE[28000]
[1045] Access denied for user
'root'#'myhostname' (using password:
YES)
Normally for a web application, you shouldn't connect to the database as root. However you tagged your post as [phpmyadmin] so I assume your issue is with, well, phpMyAdmin, in which case you might be connecting as root.
If this is the case, I see that you mentioned myhostname in your error message. Have you tried connecting to localhost instead? Sometimes the MySQL root user cannot connect from remote hosts.
you need to set some configuration variables for phpmyadmin to work:
http://www.phpmyadmin.net/documentation/Documentation.html#config
GRANT ALL PRIVILEGES ON *.* TO monty#localhost
IDENTIFIED BY 'indian' WITH GRANT OPTION;
Replace your username and password and execute it in your phpmyadmin by selecting your database.
Take a look at "5.4.7. Causes of Access-Denied Errors" in the MySQL online documentation and Using authentication modes" in the PHPMyAdmin documentation.

Categories