PHP/MYSQL Connection Problem
Moderator: General Moderators
PHP/MYSQL Connection Problem
Hi,
I am relatively new to all this. My PHP server is working and it shows MYSQL enabled. MYSQL is working because I can create and use a database. But when I try to see if they are working together using this code:
<html>
<head>
<title>connect to database</title>
</head>
<body>
<?php
$linkID = mysql_connect{"localhost","", ""};
if {$linkID !=FALSE}
{
print "The connection to the server was made successfully.";
}
else
{
print "The connection to the server failed.";
}
mysql_close{$linkID};
?>
</body>
</html>
nothing shows up in the web browser. I have tried it with and without my username and password.
Versions below
PHP 4.3.2
MYSQL 4.0.14b
Windows 2000 Service Pack 4
Apache Server
I also have the appropriate dlls' in the system directory and have edited the ini file for the MYSQL extensions. I have also restarted the Apache service.
COuld someone help? I need to be able to query a MYSQL inventory database through a browser and display the results ASAP.
Thanks.
I am relatively new to all this. My PHP server is working and it shows MYSQL enabled. MYSQL is working because I can create and use a database. But when I try to see if they are working together using this code:
<html>
<head>
<title>connect to database</title>
</head>
<body>
<?php
$linkID = mysql_connect{"localhost","", ""};
if {$linkID !=FALSE}
{
print "The connection to the server was made successfully.";
}
else
{
print "The connection to the server failed.";
}
mysql_close{$linkID};
?>
</body>
</html>
nothing shows up in the web browser. I have tried it with and without my username and password.
Versions below
PHP 4.3.2
MYSQL 4.0.14b
Windows 2000 Service Pack 4
Apache Server
I also have the appropriate dlls' in the system directory and have edited the ini file for the MYSQL extensions. I have also restarted the Apache service.
COuld someone help? I need to be able to query a MYSQL inventory database through a browser and display the results ASAP.
Thanks.
Try this:
Still nothing?
Direct Link Manual
Code: Select all
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("Could not connect: " . mysql_error());
print ("Connected successfully");
mysql_close($link);Direct Link Manual
Don't take me wrong, but that would be a long discussion, so I personally think that the best solution is to redirect you to the manuals directly. It's comprehensive enough to be easely understood.
http://se.php.net/manual/en/ref.mysql.php
Check lower down for "Table of Contents" for a quick guide.
http://se.php.net/manual/en/ref.mysql.php
Check lower down for "Table of Contents" for a quick guide.
I have a similar problem. I cannot connect to any of my tables in the database.
Any help would be appreciated, I'm kind of new at this.
<?php
// MYSQL CONNECT STRINGS
$db_user = "aplus"; //database user
$db_password = " "; //database password
$db_database = "test"; //database definition file
$db_server = "localhost"; //database server
$conn = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
print ("Connected successfully");
mysql_select_db($db_database, $conn) or die(mysql_error());
print ("Connected scucessfully");
mysql_close($conn);
?>
The error message is -
Connected successfullyAccess denied for user: 'aplus@localhost' to database 'test'
Any help would be appreciated, I'm kind of new at this.
<?php
// MYSQL CONNECT STRINGS
$db_user = "aplus"; //database user
$db_password = " "; //database password
$db_database = "test"; //database definition file
$db_server = "localhost"; //database server
$conn = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
print ("Connected successfully");
mysql_select_db($db_database, $conn) or die(mysql_error());
print ("Connected scucessfully");
mysql_close($conn);
?>
The error message is -
Connected successfullyAccess denied for user: 'aplus@localhost' to database 'test'
Try:
Might do the trick? (Notice the space in your password.) If that doesn't help, check the manual of mysql to set/update user passwords.
Good Luck.
Code: Select all
// Change
$db_password = " "; //database password
// to...
$db_password = ""; //database passwordGood Luck.
If I understood correctly, you should if it's not working check the access rights for that table. As the quote says, you have the wrong (or just cant) access that particular table.Access denied for user: 'aplus@localhost' to database 'test'
http://www.mysql.com/doc/en/Access_denied.html
Thanks for your replies and links,
I have looked through several of those pages for the answer, except the http://www.mysql.com/doc/en/Access_denied.html in my endevors to figure this out. I am not sure but http://www.mysql.com/doc/en/Access_denied.html looks like the server admisistrator information usless some of that can be run on the URL. I am using a hosting service for this and they are not real helpful.
Is there any ini files that should be included or anything. I can acess my table on line in the msqladmin with the username and password and I don't think there is a seperate password for the table.
I have looked through several of those pages for the answer, except the http://www.mysql.com/doc/en/Access_denied.html in my endevors to figure this out. I am not sure but http://www.mysql.com/doc/en/Access_denied.html looks like the server admisistrator information usless some of that can be run on the URL. I am using a hosting service for this and they are not real helpful.
Is there any ini files that should be included or anything. I can acess my table on line in the msqladmin with the username and password and I don't think there is a seperate password for the table.
I have searched the web for more information and see several ways to connect but nothing giving me any infomation on why I can connect to the database but not the table. I have the table in there even made another page to create a table and even another table with only one field.
No Luck any help would be appreciated, the hosting service is not any help, and it may not be there problem.
// MYSQL CONNECT STRINGS
$db_user = 'aplus';
$db_password = 'password';
$db_database = 'stamporder';
$db_server = 'localhost';
//CONNECT TO MYSQL
$conn = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
print ("Connected successfully");
// SELECT DATABASE TO USE
mysql_select_db($db_database, $conn)
or die("Couldn't open $db_database: ".mysql_error());
Connected successfully
Couldn't open stamporder: Access denied for user: 'aplus@localhost' to database 'stamporder'
No Luck any help would be appreciated, the hosting service is not any help, and it may not be there problem.
// MYSQL CONNECT STRINGS
$db_user = 'aplus';
$db_password = 'password';
$db_database = 'stamporder';
$db_server = 'localhost';
//CONNECT TO MYSQL
$conn = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
print ("Connected successfully");
// SELECT DATABASE TO USE
mysql_select_db($db_database, $conn)
or die("Couldn't open $db_database: ".mysql_error());
Connected successfully
Couldn't open stamporder: Access denied for user: 'aplus@localhost' to database 'stamporder'
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can connect to the database server successfully because your user has the rights to do that - you cannot access the database 'stamporder' because the user does not have the necessary permissions.
Do you have phpMyAdmin - it makes it easy to see what permissions each user has. The MySQL information on this topic is here:
http://www.mysql.com/doc/en/Privileges.html
and how to use the GRANT statement is here
http://www.mysql.com/doc/en/GRANT.html
For example to grant a user called 'test' the rights to SELECT, UPDATE, DELETE, and INSERT on the 'my_database' database, you can use the following SQL statement:
Mac
Do you have phpMyAdmin - it makes it easy to see what permissions each user has. The MySQL information on this topic is here:
http://www.mysql.com/doc/en/Privileges.html
and how to use the GRANT statement is here
http://www.mysql.com/doc/en/GRANT.html
For example to grant a user called 'test' the rights to SELECT, UPDATE, DELETE, and INSERT on the 'my_database' database, you can use the following SQL statement:
Code: Select all
GRANT SELECT, INSERT, UPDATE, DELETE
ON `my_database`.*
TO "test"@"localhost";Thank you I figured it out late last night, the database name and the user name are the same that took care of the problem. I will keep the information on the granting rights and the links posted.
$hostname="localhost";
$username="aplus";
$password="password";
$dbname="aplus";
$usertable="test";
mysql_connect($hostname,$username, $password) OR DIE
@mysql_select_db($dbname) or DIE
# Check If Record Exists
$query = "SELECT * FROM $usertable WHERE
Thank you for your posts, I am quite new to this php.
$hostname="localhost";
$username="aplus";
$password="password";
$dbname="aplus";
$usertable="test";
mysql_connect($hostname,$username, $password) OR DIE
@mysql_select_db($dbname) or DIE
# Check If Record Exists
$query = "SELECT * FROM $usertable WHERE
Thank you for your posts, I am quite new to this php.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- RobertStout
- Forum Commoner
- Posts: 32
- Joined: Wed Sep 03, 2003 5:21 pm
- Location: Your backyard.