mysql problem

Fark_Maniac

2[H]4U
Joined
Feb 21, 2002
Messages
2,438
I'm just starting out with mysql and PHP. I've bought books to step me through things and I've had c++ up through data structures, so I'm pretty confident in my php coding.

I'm running into problems with my MySQL server. I've installed it on my home workstation, which is behind a router...but I don't think that's my problem as I've opened up port 3306. I've gotten EngInSite mysql client to interact with the server as 'root' and as 'dataop' (user I wish to interact with mysql via php), but only on localhost. I have an offsite server that I've installed the client on to and 'root' may login, given the correct IP, but all other users throw an error: "Access denied".

when I try to have my php code connect at to the mysql server, anything after the mysql_connect() function is simply not parsed...like it was never there.
This is my code:
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
	$string = "Fugly <br>";
	$user = "dataop";
	$pass = "forumedited";
	echo "Dude, where's my car?<br>";
	echo $string;
	$conn = mysql_connect("localhost",$user,$pass);
	echo "Hey, it works";
	?>
</body>
</html>
This is what I get:
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Dude, where's my car?<br>Fugly <br>
I had echo's after the connect, but it never happens.

So with my attempts with the client logons and the webpage parsing, I can only assume that my server is denying the specified user access...but I don't know where to look.

Any suggestions would be greatly appreciated, whether web pages or setting suggestions. Believe me...I've googled! :eek:

EDIT: I've changed the proposed code to reflect the current file being tested and fixed typos. the file in question has my IP specified and does not use "localhost"
 
Are you sure that mysql is enabled in php? That might be why the mysql_connect isnt being parsed at all. As for the router issues, you should try connecting into the database directly using the command line mysql prompt.

Fix this:
$conn = mysql_connect("localhost","$user","$pass");

Backround reading:
http://us2.php.net/mysql_error
 
Hello. I'm currently learning PHP and MySQL as well. One question though, in the books and what not that I'm going through they use mysqli_connect (or for the object oriented approach mysqli class), so is that what you are using? If not then maybe there's similar functions to the mysqli ones I've listed below...

Code:
$conn = mysql_connect("localhost","user","$pass");
if(mysqli_connect_errno())
{
   echo 'Error: Could not connect to database.  Error No.: '.mysqli_connect_errno();
   exit;
}

This or the equivalent mysql_connect functions should at least tell you if it's even connecting to your database. I had similar problems where the script appeared to go no further than the connection to the database and once I found out that it was the connection that was erroring out and what that error was I figured out how to fix it.
 
Fark_Maniac said:
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
	$string = "Fugly <br>";
	$user = "dataop";
	$pass = "editedout";
	echo "Dude, where's my car?<br>";
	echo $string;
	$conn = mysql_connect("localhost","user","$pass");
	echo $conn;
	mysql_close($conn);
	echo "connection closed";
	?>
</body>
</html>

Hi am just learning php myself, after glancing at the line where your trying to connect to the database the line should look more like this: -
PHP:
$conn = mysql_connect("localhost",$user,$pass);

I recommend you learn the basic syntax then move on to more advanced stuff like databases.
 
Wiseguy2001 said:
Fark_Maniac said:
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
	$string = "Fugly <br>";
	$user = "dataop";
	$pass = "editedout";
	echo "Dude, where's my car?<br>";
	echo $string;
	$conn = mysql_connect("localhost","user","$pass");
	echo $conn;
	mysql_close($conn);
	echo "connection closed";
	?>
</body>
</html>

Hi am just learning php myself, after glancing at the line where your trying to connect to the database the line should look more like this: -
PHP:
$conn = mysql_connect("localhost",$user,$pass);

I recommend you learn the basic syntax then move on to more advanced stuff like databases.
well well...I'm sorry for the typo. I checked my code (that I edited to post in here) and it was correct. I would assume that even if the fucntion failed, it would still parse the rest of the page/script and not abort the whole thing right at that point.


Wuggle, thanks for the heads up about enabling mysql in the php.ini file...I hadn't done that. I have enabled it in the ini file and in the PATH windows environment variable...but still doesn't work. I'm going to try to restart the machine, will post if that gets things going.

the file I'm working on is: THIS

Edit: a reboot did not help (was thinking of the path environment variable). at anyrate, still cannot connect to the mysql directly from a remote machine w/ user that is to do this in php. I'm thinking I have to correct this problem first.
 
BTW, mysql_error() gives a human-readable error message. Something like
Code:
if (!$conn) echo mysql_error();
at the right place should make things easier.

And yes, you do want to fix that MySQL-login-problem first. :)
 
Does the user you are trying to connect with have the proper priveledges?
 
I had created a 2nd user and, via the client, gave them all priveledges. Should there be a certain priveledge I should be looking for specifically?

I took a quick look at the privilages between the 2nd user I created and root and there are some privs that are not the same...hrm
 
Fark_Maniac said:
well well...I'm sorry for the typo. I checked my code (that I edited to post in here) and it was correct. I would assume that even if the fucntion failed, it would still parse the rest of the page/script and not abort the whole thing right at that point.

I was trying to help, there where errors all over the place with the code you posted. That’s why I said 'learn the basics first'.

No need to get all touchy
 
Wiseguy2001 said:
I was trying to help, there where errors all over the place with the code you posted. That’s why I said 'learn the basics first'.

No need to get all touchy
well, from what you had pointed out, there was one error, which was a typo...granted in programming, typos can lead to big and crazy errors. What are the other errors? From what I see, you only pointed out the typo.
It is all in the presentation, the way it was worded, didn't exactly make you sound like the most friendliest person around. I've been told that it isn't what you say, but what the other person understands. But I do sincerely thank you for making the effort to help.
 
To rule out permissions, try connecting to your mysql server from your webserver through a command line prompt. Theres usually a mysql.exe in one of the folders. I think the synax is something like "mysql -u user -h server_ip (-p if you have a password) database_name". Once you have that working, just make sure that you're using that login/pass in PHP.

To see if PHP is picking up mysql, create a new php file and call the phpinfo() function and see if it says anything about mysql.

Do you get anything from mysql_error()?
 
wuggle said:
To rule out permissions, try connecting to your mysql server from your webserver through a command line prompt. Theres usually a mysql.exe in one of the folders. I think the synax is something like "mysql -u user -h server_ip (-p if you have a password) database_name". Once you have that working, just make sure that you're using that login/pass in PHP.

To see if PHP is picking up mysql, create a new php file and call the phpinfo() function and see if it says anything about mysql.

Do you get anything from mysql_error()?

the remote server I'm using does not have mysql, it is strictly a html/file server for now (mainly used as a game server), however, I have altered the users with '%' instead of 'localhost' and am now able to logon remotely via the client from my remote server...so now I know I can login remotely. One problem down.

your 2nd item about looking at phpinfo made me notice that I was editing the wrong php.ini file...I replaced it and have finally got mysql running.

With the above worked out, it spits out the error:
Dude, where's my car?
Fugly
Client does not support authentication protocol requested by server; consider upgrading MySQL clientHey, it works

I'm getting closer!

oh, and don't worry. This is just my dev environment...what I'll be hosting the site on is a tried and true php/mysql server config. ;)

thanks all for the suggestions and help.

Edit: I'm pretty sure I had installed mysql 4.1.xxx...but it returns 3.23.57 in the phpinfo...
Edit2: when I log in to the mysql server via mysql.exe command prompt..I get this:
Your MySQL connection id is 6 to server version: 4.1.13-nt. I'm a bit confused with the difference in version numbers.
 
http://dev.mysql.com/doc/mysql/en/old-client.html

Yep, you just need to upgrade the mysql on your webserver. If you're 100% its already installed, check to see if PHP is seeing the right version.

It might be a good idea to check to see which PHP/mysql versions your final server will be running. Trust me, it sucks when you develop in 4.1 and the final server is just 3.23 (with no subqueries, AHH) :(

Edit: which machine are you running mysql.exe from?
From what I can tell, you have 4 machines:
Your local machine
Your webserver - PHP + mysql client
Your DB - mysqld
Your final webserver - PHP + mysql client

what versions of mysql are installed where?
 
I have two machines currently:
1st machine:
My workstation has http/php/mysql installed on it that I'm using as a dev envinronment

2nd Machine:
My game server that just has http(apache) installed as well as remote desktop software where I can run clients to connect back to my workstation. I am only using this for verification that everything works external of my private network.


Eventually, the production server will be a friend of mine's that is donating the space for the project.


The only place I installed mysql anywhere was on my server, and that was latest and greatest 4.1 from mysql.com website.

Edit:
I've logged in to the workstation mysql via my client software and pulled this out of the log:
Connection established
Ask server version...4.1.13-nt
EngInSite MySQLClient v 4.0
It is acting like the php/web browser is seeing a different and older version than what the client is logging into...
 
What is the value for 'Client API version' under MySQL in phpinfo()?
 
I've redownloaded 4.1.13a and reinstalled that...phpinfo is still reporting the old version and when I login via command line...still the newer version....this is getting rediculus.
 
If you can access the MySQL server with the client, and it reports the correct version, then it appears that MySQL isn't the problem here, but PHP, or possibly something else.

Which version of PHP are you using? 4.x or 5.x? If it's 5.x, then it might be that you've got an old version of the MySQL dll(s), which is confusing PHP.
 
that was it!! upgraded to PHP 5.0.4...the old libmysql.dll file was 2xxKB large...the new one was over 1MB...it all works now. Thank you very much guys for going through my growing pains.

you guys are awesome.
 
Fark_Maniac said:
that was it!! upgraded to PHP 5.0.4...the old libmysql.dll file was 2xxKB large...the new one was over 1MB...it all works now. Thank you very much guys for going through my growing pains.

you guys are awesome.
I suddenly feel less bad about wasting precious hours on getting MySQL working on my system. So far it's the only thing about migrating from PHP 4 to 5 which had me nearly ready to give up on PHP 5 :D
 
Back
Top