Jump to content

Sql query = "false"


Chill_user
 Share

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!

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

1 minute ago, Amantha Bill said:

Working perfectly (2d code), thanks!

3d code now.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More