SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: mysql connection issue
-
Jul 16, 2002, 15:53 #1
- Join Date
- Jul 2002
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
mysql connection issue
Hey,
I just bought the sitepoint book about PHP & MySQL by Kevin Yank And trying to set up a page that will connect to a mysql database and select data from a table.
Here's some background info:
I have MySQL and PHP running on Win2000 server (192.168.1.1) and telnet service running. I am able to connect to mysql via telnet from another machine on my network (btw, none of this is accessible through the firewall) I am not able to connect to mysql via a php string.
I followed the steps in Ch. 4 verbatim, but I am getting this error:
Unable to connect to the database server at this time.
Access denied for user: 'root@MYCOMPUTERHOST.com' (Using password: YES)
I used this line:
PHP Code:$dbcon = mysql_connect("192.168.1.1", "root", "[mypasswd]");
What's up with my code? Oh, here is the actual code in the page if that helps:
PHP Code:<html>
<title>View Blackbook</title>
<body>
<?php
//Connect to database
$dbcon = @mysql_connect("192.168.1.1" , "root" , "**mypass**");
if (!$dbcon) {
echo( "<p>Unable to connect to the database server at this time.</p>" . mysql_error() );
exit();
}
echo("$dbcon");
// Select the blackbook database
if (!@mysql_select_db("blackbook", $dbcon) ) {
echo( "<p>Unable to locate the Blackbook " . "database at this time.</p>" );
exit();
}
?>
<p> here is your listing</p>
<blockquote>
<?php
// Request the text of members table
$result=@mysql_query("select firstname, lastname, email, username, street1, city, state, zip, hphone from members");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
// Display the address listings
while ( $row = mysql_fetch_array($result) ) {
echo("<p>" . $row["firstname, lastname, email, username"] . "</p>");
}
?>
</blockquote>
</body>
</html>
PHP Code:echo( "<p>Unable to locate the Blackbook " . "database at this time.</p>" );
-
Jul 17, 2002, 06:15 #2
- Join Date
- Jul 2002
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
selecting DB
Ok,
I think I have figured out the connection issue. I am now returning a '1' in $dbcon and no error message displays. The password thing was incorrect (though I don't know how it got that way!!)
Now the next error is that it can not find the database I named in the sql command string. Everything is lowercase (though I don't think that matters unless you're using *nix-based installs)
Again, I can telnet into mysql and can use [database]; and then show tables; without a problem. It's just when I try to do that using PHP.
Any guru's wanna take a stab at this?
-
Jul 17, 2002, 06:21 #3
- Join Date
- Jun 2001
- Location
- Before These Crowded Streets
- Posts
- 9,446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
it looks fine to me. Just make sure your spelling is correct and yes, even in Windows, MySQL AND PHP are case-sensitive. They are both ports out of Unix and so the same rules apply.
sKetch
-
Jul 17, 2002, 06:53 #4
- Join Date
- Jul 2002
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Looks fine... don't work tho
Hey,
I have triple checked all the syntax and case... I copied the dang thing straight out of the book and it don't work.
Just for kicks, I downloaded the code-archive from sitepoint and used the exact same jokes.php script only modifying the host, user, pass and db sections. Same problems.
Now that I am able to connect (or so I think) to the database, it still can not locate the database... hmmm.
I have seen other PHP scripts that use the 'OR DIE("msg"); on the end of a line. Is this the ultra short version of the if the command returns false, to stop the script and display the error?
As you might assume, I am a newbie in PHP and MySQL. If the script right out of the book don't work... what's a guy to do!?
-
Jul 17, 2002, 07:40 #5
- Join Date
- Aug 2000
- Location
- Thailand
- Posts
- 4,810
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Take out the "@'s" and see what message you get....
~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
-
Jul 18, 2002, 06:49 #6
- Join Date
- Jul 2002
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nope didn't help
I took out the '@'s and still had the unknown database error. It's weird because I know the database is there, and I know I spelled it right.
This doesn't seem that hard. I understand what the book is saying and I have coded right.
Has anyone here gone through the Sitepoint book on PHP and MySQL chapter 4 and setup the jokes database and tried to make these pages? Did they work? What setup did you use for PHP and MySQL (I am using the latest stable distros on win2K Server)
I hate to sound like I am begging (very unbecoming) but someone smarter than me has to know what the f**k I am doing wrong
Try the page yourself
The code is listed previously in this thread.
Bookmarks