Jump to content

Sql query = "false"


Chill_user

Recommended Posts

Hello to all,

I have next query which gives "false" result, but data exists in the table.

$search_param = "test";
$query = 'SELECT *
        FROM `'._DB_PREFIX_.'test` 
        WHERE `link_rewrite` = '.$search_param;
$result = Db::getInstance()->ExecuteS($query);

If I make "Select *" from table = all is working.

Whats the problem with showed before code?

 

Thanks a lot!

Link to comment
Share on other sites

$search_param = "'%".test."%'";
$query = 'SELECT *
        FROM `'._DB_PREFIX_.'test` 
        WHERE `link_rewrite` LIKE '.$search_param;
$result = Db::getInstance()->ExecuteS($query);

or

$search_param = "'".test."'";
$query = 'SELECT *
        FROM `'._DB_PREFIX_.'test` 
        WHERE `link_rewrite` = '.$search_param;
$result = Db::getInstance()->ExecuteS($query);

or

$search_param = 'test';
$query = "SELECT COUNT(`link_rewrite`) AS count
        FROM `"._DB_PREFIX_."test` 
        WHERE `link_rewrite` = ".$search_param;
$result = Db::getInstance()->getValue($query);

if ($result['count'] == '0') {
        echo 'URL rewrite: '.$search_param.' not exists';
    } else {
        echo 'URL rewrite: '.$search_param.' exists in databse. Count: '.$result['count'];
    }

 

Edited by Guest (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...