Solved

error when attempting to connect to MySQL with PHP

Posted on 2007-11-13
6
2,943 Views
Last Modified: 2013-12-13
I am using Windows Small Business Server 2003 with IIS 6.0.  I am attempting to connect to a mysql database using the following code:

$conn = mysqli_connect('192.168.1.x', 'root@localhost', 'password', 'database');

I have also created another user account, and provided all privileges to the account in the MySQL client.  I then tried connecting with the new user account with the same error message

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'root@localhost'@'cogent-s1.CogentMedia.local' (using password: YES) in C:\StuffLocator\email_verification.php on line 20
Access denied for user 'root@localhost'@'cogent-s1.CogentMedia.local' (using password: YES)

I have checked the php.ini to ensure that the extension=php.mysqli.dll is uncommented and that the php.mysql.dll is in the extensions folder.

I appreciate all help that can be provided.  
0
Comment
Question by:GarrettChristopherson
  • 3
  • 3
6 Comments
 
LVL 3

Accepted Solution

by:
samalraj earned 500 total points
ID: 20277831
Hi,
      can you try this

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'databaseName';

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $conn);

just give tn user name as root no need the domain like root@localhost
0
 
LVL 5

Author Comment

by:GarrettChristopherson
ID: 20277885
I noticed that you are using mysql_connect instead of mysqli_connect (with the i after the mysql part).  My reading has taught me that mysql is for older versions of PHP and MySQL, and does not include all of the new functions and OOP properties of the mysqli package.  

I tried using variables instead of place just the values into the mysqli_connect method:

$localhost = 'localhost';
$username = 'root';
$password = 'password';
$database = 'db';
 $conn = mysqli_connect('$localhost', '$username', '$password', '$database');

and got this error:

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host '$localhost' (11004) in C:\StuffLocator\email_verification.php on line 24
Unknown MySQL server host '$localhost' (11004)

Is there something that I have to do in the MySQL client to get the localhost linked to the database?
0
 
LVL 5

Author Comment

by:GarrettChristopherson
ID: 20277937
t tried the following code:

$localhost = 'localhost';
$username = 'root';
$password = 'ljfs531ljfs531';
$database = 'test_001';
 $conn = mysql_connect('$localhost', '$username', '$password');
mysql_select_db($database, $conn);

and received the following errors:

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host '$localhost' (11004) in C:\StuffLocator\email_verification.php on line 24

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\StuffLocator\email_verification.php on line 25

This was using the older mysql_connection. any ideas
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 3

Assisted Solution

by:samalraj
samalraj earned 500 total points
ID: 20277994
Hi,
      when using variable you don't have to use single quote
instead of
 $conn = mysqli_connect('$localhost', '$username', '$password', '$database');
use
 $conn = mysqli_connect($localhost, $username, $password, $database);
0
 
LVL 5

Author Comment

by:GarrettChristopherson
ID: 20278033
Thanks, now I have other problems with other sections of the code, but at least I'm connecting now.  thanks for your help!
0
 
LVL 3

Expert Comment

by:samalraj
ID: 20278056
Welcome, I am happy to assist you.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question