"not a valid MySQL result resource"

admin

Administrator
Staff member
Can't seem to get select statements to work with PHP 4.0.3pl1 and MySQL 3.23.27-beta.

Given the following code:

=======================================
mysql_pconnect() || die (": " . mysql_error());
mysql_select_db("choppiri");

echo "<h3>trying INSERT statement</h3>";

$res = mysql_query("REPLACE into users (user_id, name, password) VALUES (1000, 'fred', 'fred_pw')")
|| die ("INSERT failed: " . mysql_error() );
echo "affected rows: " . mysql_affected_rows();

echo "<h3>trying SELECT statement</h3>";

$res = mysql_query( "SELECT name, password FROM users" ) || die ("Query failed :" . mysql_error());

while ($row = mysql_fetch_row($res)) {
echo "* user_id: $row[user_id], name: $row[name], password: $row[password]<br>";
}

echo "<h3>trying non-table SELECT statement</h3>";

$res = mysql_query( "SELECT 1 + 1 AS total" ) || die ("Query failed :" . mysql_error());
if (! $res ) {
echo "No result passed!: " . mysql_error();
} else {
$row = mysql_fetch_row($res);
echo "1 + 1 = $row[total]<br>";
}
=======================================

I get the following output:

----------------------------------
trying INSERT statement

affected rows: 2

trying SELECT statement


Warning: Supplied argument is not a valid MySQL result resource in **script** on line 42

trying non-table SELECT statement


Warning: Supplied argument is not a valid MySQL result resource in **script** on line 52
1 + 1 =
----------------------------------

NB:
Line 42: while ($row = mysql_fetch_row($res)) {
Line 52: $row = mysql_fetch_row($res);


The INSERT command is working fine, so I know that there's not a db connectivity issue. I've tried logging into the database as the apache user and copy-pasting the select statements, and of course they work fine. That and the fact that even the "1 + 1" select doesn't work makes me think that this isn't a permissions problem.

Am I doing something completely boneheaded here?

TIA
 
Back
Top