Posted on: 02/25/05 01:38pm
By: Anonymous (windf4ll)
I created a php enabled static page that had the following 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?
Problem using mysql_connect in static page
Posted on: 02/25/05 01:50pm
By: Dirk
I'd rather say it's the extra ) after mysql_error() ...
For future reference:
Blank page[*1]
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
Problem using mysql_connect in static page
Posted on: 02/25/05 03:08pm
By: Anonymous (windf4ll)
[QUOTE BY= Dirk] I'd rather say it's the extra ) after mysql_error() ...
[/QUOTE]
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.
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
Problem using mysql_connect in static page
Posted on: 02/25/05 03:11pm
By: Anonymous (windf4ll)
The (with the addtion) part was supposed to say with the addition of the
<?php ?>
tags
Problem using mysql_connect in static page
Posted on: 02/25/05 03:21pm
By: Dirk
[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.[/QUOTE]
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
Problem using mysql_connect in static page
Posted on: 02/25/05 03:26pm
By: Anonymous (windf4ll)
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!