I've been having a weird problem today (and maybe it's been there all along,
just haven't's only been live a few days).  I have a web page
that allows users to query my database by either subject or alphabet (A-Z).
Today (and I think I noticed it once before but didn't pay much attention),
if you do a query, the first time it comes back with the results.  The
second time, clicking the same letter (or sometimes other letters), for
instance, it comes back with a "Database Not Selected" error.  Or, every
time in a row for a dozen times it comes back with a "Database Not Selected"
error.  Or, sometimes it comes back with the results just fine for twenty
times in a row. Or, ...

You get the idea.  It doesn't happen all the time, just sometimes, and in no
particular order.  Very strange because I'm not changing a dang thing.
Anyway, I've already tried rebooting the server, no change.  And, I've tried
accessing the web page from other machines, same problem.  Has anyone ever
run into this?

I'm running Red Hat 7.2, Apache 1.3.23, MySQL 3.23.49a, and PHP 4.2.1.

Here's the code in the web page with only some name changes (for security,
ya know):

function Query()
                global $mydb, $recordset, $total_rows, $letter;
                $letter = $_GET['letter'];
                mysql_select_db($database_mydb, $mydb);
                $query = sprintf("SELECT name
                                        FROM tbl_mytable
                                        WHERE name LIKE %s
                                        ORDER BY name ASC",
                                        SQLStr($letter . "%", "text"));
                $recordset = mysql_query($query, $mydb) or die(mysql_error());
                $total_rows = mysql_num_rows($recordset);

And then the code in my include where I keep all the db connection stuff:

$hostname_mydb = "localhost";
$database_mydb = "mydb";
$username_mydb = "user";
$password_mydb = "xxxxxxxx";
$mydb= mysql_pconnect($hostname_mydb, $username_mydb, $password_mydb) or

Any help is appreciated!!  Thanks!


PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to