What is the error in the query below?

I wrote the following query in Drupal6.

$sql = 
    "SELECT registryvalue 
    FROM {muln_registry} 
    WHERE fk_applicationid = %d 
    AND registrykey = '%s'";

$result = db_result(db_query($sql, 32, 'SHOW_SCORE_TO_STUDENT'));

It is supposed to return a value of 1. But it does not display anything. If I copy and run in mysql editor, it returns correctly.

But now he gives an empty. There are no errors in connecting to the database, etc. Since other queries work fine.

What could be a mistake here?

+5
source share
5 answers

All I see is a mistake due to {}

it should be

 $sql = "SELECT registryvalue FROM muln_registry WHERE fk_applicationid = %d AND registrykey = '%s'";
0
source

Try

echo '<pre>';
var_dump(db_query($sql, 32, 'SHOW_SCORE_TO_STUDENT'));
echo '</pre>';

And look what data is in the descriptor. This may give you a better idea of ​​what is going wrong. My suggestion is to switch to PDO, but I know that this will not be a valid option when the system already uses a different database engine.

0

"SHOW_SCORE_TO_STUDENT" , :

$sql = "SELECT registryvalue FROM {muln_registry} WHERE fk_applicationid = '%d' AND registrykey = 'SHOW_SCORE_TO_STUDENT'";

" , , , ?

0

You should try the LIKE operator to find a patter. For example, it WHERE column_name LIKE '%searchString'will search where the entry begins with searchString.

For more information on how you can search for it.

-1
source

use:

$sql     = "SELECT registryvalue FROM muln_registry WHERE fk_applicationid = %d AND registrykey = '%s'";

instead

$sql     = "SELECT registryvalue FROM {muln_registry} WHERE fk_applicationid = %d AND registrykey = '%s'";

{} curly braces have been removed.

-2
source

All Articles