SELECT *
FROM `enzymes`
INNER JOIN `compounds`
ON compounds.compound_id = enzymes.compound_id
WHERE `ec` LIKE '1.11%'
it works in phpmyadmin and mysql workbench.
It won’t work regardless whether I backtick everything use mysql_real_escape_string and add the database name where appropriate. the phpmyadmin php code won’t work either.
ERRORS: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in….
same error for all other query-resource dependent functions
Upd:
case 'ec':
$dbl = mysql_connect(DB_ADDRESS, DB_USER, DB_PASSWORD);
mysql_select_db("kegg", $dbl);
//a)connection is fine
//b)tried with explicitly providing the db name vs with pre-selection
$sql = "SELECT * FROM enzymes INNER JOIN `compounds` ON compounds.compound_id=enzymes.compound_id";
print_r($sql);
$result = mysql_query( $sql, $dbl);
print mysql_error ($dbl);
while ($row = mysql_fetch_assoc($result)) {
print_r($row)
$items[ $row['name'] ] = $row['compound_id'];
}
,,,
Solution: Thanks everyone,- Brad gave the crucial answer first.
$sql = "SELECT enzymes.*, compounds.*\n"
. "FROM enzymes\n"
. " INNER JOIN compounds\n"
. " ON compounds.compound_id = enzymes.compound_id\n"
. "WHERE enzymes.ec LIKE '1.11%' LIMIT 0, 30 ";
A similar topic came up recently where it was suggested that it only works when selecting specific fields. The crucial solution when all data is desired is to resolve ambiguities to:
enzymes.*, compounds.*
My gut is telling me the database is confused by your column references. When you start doing joins, and especially when you have columns names that may match, it’s good practice to be explicit on what you’re selecting, comparing, etc. e.g.
But, without knowing the exact error that’s occurring, this can only be a guess.UPDATE
Now that I see the error, make sure you’re testing for a proper query response. When you call
mysql_query(or whatever you use), check the resource for failure before trying to fetch the result. Most connection libraries have a *_error or *_last_error method you can call to see what caused the failure.