GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-May-2007, 14:10
Kirath Kirath is offline
New Member
 
Join Date: Dec 2006
Posts: 10
Kirath is on a distinguished road

mysql_connect() problem


I'm extremely frustrated at the moment. This code works fine on my server, but on a different one it doesn't work. I get no error message from mysql or php, but just a page cannot be found error. If I comment out mysql_connect I will get the "Unable to select database" as I should, but with the mysql_connect call in there, I get the page cannot be found. What is causing this?

- php 4.4.7
- mysql 5.0.1
- php is configured with mysql
- the username in question is set in mysql to be allowed to connect remotely


PHP Code:

<?
$username = "user";
$password = "pw";
$database = "USERLOGINS";

mysql_connect(localhost,$username,$password) or die(mysql_error());
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM USERLOGINS";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {

$login=mysql_result($result,$i,"username");
print("<b>$login </b><br>");

$i++;
}
?>


Thank you in advance for any ideas.
Last edited by LuciWiz : 14-May-2007 at 14:56. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 14-May-2007, 16:17
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,232
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: mysql_connect() problem


Any OS difference between the servers?

In the connect, try 'localhost' [with quotes], or possibly even '127.0.0.1'.
I can't specifically remember the issue, but I seem to recall a similar problem several months back where localhost, even if provided as a string, didn't work.

Here's a note about localhost from php.net with mysql_connect:
Code:
Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as mysql.default_host string in your PHP configuration and leave the server field blank.

HTH
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 14-May-2007, 16:37
Kirath Kirath is offline
New Member
 
Join Date: Dec 2006
Posts: 10
Kirath is on a distinguished road
Question

Re: mysql_connect() problem


Hi Turbo, thanks for taking the time to reply. I have tried localhost, 'localhost', "localhost", "127.0.0.1", and "127.0.0.1:3306" all to no avail. There is a difference in OS between the two servers, one is Debian linux, and this is AIX 5.3 (which I really have never cared for much, this being yet another issue perhaps).

I log into MySQL from the command line, and the connection ID numbers are being incremented after refresh attempts of this page.. so apparently there is a connection being made, or does this happen even with an unsuccessful connection? It still baffles me however why this line is causing the page load problem.
  #4  
Old 14-May-2007, 19:42
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,232
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: mysql_connect() problem


I'm not sure what all you might need for AIX, but, I did find something that might be helpful, see here:
http://www-128.ibm.com/developerwork.../au-mysql.html

There were more hits, just google this phrase: "mysql on aix"
and you'll see others, that might possibly be better.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 15-May-2007, 07:10
Kirath Kirath is offline
New Member
 
Join Date: Dec 2006
Posts: 10
Kirath is on a distinguished road
Question

Re: mysql_connect() problem


I just realized there is no mysql.so on the system. Shouldn't this have been built when php was built configured for --with-mysql?
  #6  
Old 15-May-2007, 09:04
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,232
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: mysql_connect() problem


Depends on how it was configured, I assume:
Quote:
PHP 4

The option --with-mysql is enabled by default. This default behavior may be disabled with the --without-mysql configure option. If MySQL is enabled without specifying the path to the MySQL install DIR, PHP will use the bundled MySQL client libraries.

Users who run other applications that use MySQL (for example, auth-mysql) should not use the bundled library, but rather specify the path to MySQL's install directory, like so: --with-mysql=/path/to/mysql. This will force PHP to use the client libraries installed by MySQL, thus avoiding any conflicts.
Not sure where the "bundled MySQL client libraries" would be placed, though.

EDIT:
I would think that if you have both PHP, and MySQL installed (it appears that you do from the first post, but is this true for BOTH systems?) then there shouldn't be a problem. The --with-mysql merely allows PHP to interface with MySQL, but does NOT install MySQL.

Try this: type 'mysql -V' (no quotes) at the command prompt, and see what it replies.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
Last edited by TurboPT : 15-May-2007 at 09:35.
  #7  
Old 15-May-2007, 11:30
Kirath Kirath is offline
New Member
 
Join Date: Dec 2006
Posts: 10
Kirath is on a distinguished road

Re: mysql_connect() problem


Hi Turbo. Yes, MySQL is installed and running. Like I said, attempts to load the index.php page increments the connection IDs in MySQL. So it SEEMS like it is connecting, but yet still barfs out the broken 'page cannot be displayed' when the mysql_connect() line is not commented out.

Code:
Your MySQL connection id is 146 to server version: 5.0.27-standard Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>


output of mysql -V:
mysql Ver 14.12 Distrib 5.0.27, for ibm-aix5.2.0.0 (powerpc) using readline 5.0


This has to be something *really* stupid (Isn't it always?!!)
  #8  
Old 15-May-2007, 16:10
Kirath Kirath is offline
New Member
 
Join Date: Dec 2006
Posts: 10
Kirath is on a distinguished road

Re: mysql_connect() problem


Okay well, I got totally frustrated with this today and just blew everything out and started from scratch. After banging my head against a few things I got PHP to compile and link and finally everything is working. I wish I could have figured out what that problem was, but the important thing is it's working now. Thanks Turbo for your input and time!
  #9  
Old 15-May-2007, 20:06
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,232
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: mysql_connect() problem


Yeah, I had sort of a similar issue with VC++ Express. It has been installed and working well for over a year (going on two, really), and about two months ago, the IDE crashed when trying to compile (or execute from the IDE) any trivial program -- like one of their 'getting started' programs, or even a basic project skeleton generated by their wizard!

I never figured out what caused the IDE to suddenly die. It took a repair install, AND re-installing the associated service pack to get it all working again. Go figure.

But anyway, since it works now, that should make you fell like:, I know I did.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Graphic problem in Unreal Tournament 2004 zerox Computer Software Forum - Games 10 09-Oct-2005 12:31
Runtime Problem involving "printf" in C Program supamakia C Programming Language 2 09-Oct-2005 10:09
a significant problem after installing Xp mohammad Computer Software Forum - Windows 10 09-Aug-2005 07:03
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 07:53

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:37.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.