Welcome to Geeklog, Anonymous Thursday, November 28 2024 @ 07:40 am EST

Geeklog Forums

Problem using mysql_connect in static page


windf4ll

Anonymous
I created a php enabled static page that had the following code:
Text Formatted Code

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

 


where mysql_user and mysql_password are valid entries and I am able to connect to the mysql server from a command line using the standard:

mysql -u mysql_user -p
mysql_password

I have tried both "ececute PHP' and 'execute PHP (return)' and both result in a blank page when I click on the Display Page link for the static page - and by blank I mean a completly blank web page (nothing but white).

I have also tried a simple "Hello World' php static page, just to make sure I know what I'm doing and everything worked fine. So I'm assuming it's a problem with the mysql_connect. Any ideas what could be going on here?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
I'd rather say it's the extra ) after mysql_error() ...

For future reference: Blank page

Btw, if the database is the same that also holds the Geeklog tables, you could use Geeklog's MySQL wrapper functions - no need to connect to the database again.

bye, Dirk
 Quote

windf4ll

Anonymous
Quote by Dirk: I'd rather say it's the extra ) after mysql_error() ...


What extra )? One is for the mysql_error and the other closes the Die. I was able to run the exact code (with the addition) from the command line without error.


For future reference: Blank page


Thanks for that. My php.ini already had the error reporting turned on and I tried adding the line to lib-common.php and still no luck. Any other ideas?


Btw, if the database is the same that also holds the Geeklog tables, you could use Geeklog's MySQL wrapper functions - no need to connect to the database again.


It is not the same database. I tired using the Geeklog wrappers, but ran into problems with hit counting, since the database I want to query does not contain the gl_vars table. I thought about either adding my database to the Geeklog dB, or building the required gl_ tables in my database, but thought I'd try just connecting to the database again. Do you think this might be my problem - that I'm connecting again?

Thanks for your help - this is a great piece of software.
Jim
 Quote

windf4ll

Anonymous
The (with the addtion) part was supposed to say with the addition of the
Text Formatted Code
<?php ?>
 
tags
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by windf4ll: What extra )? One is for the mysql_error and the other closes the Die. I was able to run the exact code (with the addition) from the command line without error.

You're right. Sorry about that ...

Well, there's always the good ol' printf() debug method. Or, in Geeklog terms, COM_errorLog. I.e. do a COM_errorLog call after each line and then check error.log to see which lines were actually executed.

bye, Dirk
 Quote

windf4ll

Anonymous
Think I figured it out...

The problem appears to be with the mysql_close at the end - even though I was specifying mysql_close($link), it looks like it was closing everything. So first, I tried just removing that line, and it worked.

I then replaced mysql_connect with mysql_pconnect - this should be a better way to go, right? Then (as suggested in the PHP docs) mysql_close does nothing, and the script works (with mysql_pconnect it works with or without the mysql_close - pconnect just ignores the close).

Thank you for your suggestions - now back to playing with this thing!
 Quote

All times are EST. The time is now 07:40 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content