How to combine these two credentials Queries? - mysql

I wanted to make this two queries into one query. The purpose of the query is to check if the credentials match in either of the table "user_credentials" or "workers". How can I do so?
SELECT user_name FROM user_credentials WHERE user_name = '$user_email'
AND password = '$user_password'
SELECT user_name FROM workers WHERE user_name = '$user_email'
AND password = '$user_password'

try this
SELECT user_name FROM user_credentials WHERE user_name = '$user_email' AND password = '$user_password'
union
SELECT user_name FROM workers WHERE user_name = '$user_email' AND password = '$user_password'
then check mysqli_num_rows or mysql_num_rows

Related

case sensitive select query in mysql

Here Problem is make sql query is not check case sensitive latters
Here SQL Version;
VERSION(): 8.0.15
Sql Query for login user:
SELECT COUNT(*) as cnt FROM accounts WHERE (number = 'AdMin' OR email = 'AdMin') AND password = '******' AND type IN (1) AND deleted = 0
Database store name='admin'
here how to set case sensitive sql query for mysql 8.0 and stop login when username ='AdMin'
You need to use the BINARY operator to make your search case sensitive:
SELECT COUNT(*) as cnt
FROM accounts
WHERE (number = BINARY 'AdMin' OR email = BINARY 'AdMin') AND password = '******' AND type IN (1) AND deleted = 0
Demo on dbfiddle

Db queries of OIM

DB query to check Account status of the user
DB query to check Entitlement status of the user
DB query to check Role and Access Policy mapping.
Please let me know if anyone have these queries?
For Account status
SELECT usr.usr_login,obj.obj_name,ost.ost_status
FROM orc, usr, obj, oiu, ost, obi WHERE orc.orc_key = oiu.orc_key AND oiu.usr_key = usr.usr_key AND oiu.ost_key = ost.ost_key
AND oiu.obi_key = obi.obi_key AND obi.obj_key = obj.obj_key AND obj.obj_name='ABC' order by usr.usr_login
Entitlement status of the user
select usr.usr_login,ENT_LIST.ent_display_name,
ENT_LIST.ent_value,ENT_ASSIGN.ent_status
from ENT_ASSIGN, usr, ENT_LIST where usr.usr_key = ent_assign.usr_key and
ENT_LIST.ent_list_key = ENT_ASSIGN.ent_list_key
and ENT_LIST.ent_value like 'ABC' order by usr.usr_login,ENT_DISPLAY_NAME;
Role and Access Policy mapping
select pol.pol_name, poc.poc_field_value from pol, poc where poc.pol_key = pol.pol_key AND poc.poc_field_name = 'ABC' order by pol.pol_name, poc.poc_field_value
To check Role assigned to User
select usr.usr_login, ugp.ugp_name from usg usg left outer join usr usr on (usg.usr_key = usr.usr_key)
left outer join ugp ugp on (ugp.ugp_key = usg.ugp_key)
where ugp_name ='ABC'

MySQL CASE/IF usage

My application currently connects to MySQL and performs this query:
select nickname
from users
where nickname = '$nick' and password = '$pass'
$nick and $pass are inserted by the application.
I need to advance this query to do the following:
If the where nickname = '$nick' and password = '$pass' returns a row just return the row as usual.
If the where nickname = '$nick' and password = '$pass' return 0 rows, I need it to check whether the '$nick' is present, and it is the fact that '$pass' is wrong that there are 0 rows, if this is the case then return 0 rows, other wise if there is no '$nick' in the table, return the row anyway.
i.e. if nickname is in the table and the password is correct, or the nickname isn't in the table, return a row. Otherwise if nickname is in the table and the password is not correct, return 0 row.
Is this possible using MySQL?
Try this:
select nickname
from users
where nickname = '$nick' and password = '$pass'
union
select '$nick' as nickname
from users AS t1
where not (nickname = '$nick' and password = '$pass') and
not exists (select 1
from users
where nickname = '$nick')
Demo here

Zend Framework - and in where clause

I am working on Zend Framework, got 1 problem in query, i want to fetch userid from tbl_user & want to check record with And in where clause
here is my query
$sql=$this->select()->from(users)->where('email = ? ', trim($email) , 'password = ?', md5(trim($password)) );
when i am printing query it prints
select * from users where email = 'test#gmail.com';
i want to print query like
select * from users where email = 'test#gmail.com' AND password='123456';
thanks in advance
You were close. You just need to call the where() method twice:
$this->select()->from(users)->where('email = ?', trim($email))
->where('password = ?', md5(trim($password)));

How to use Boolean logic in a mySQL SELECT query

How can I check if email = '$e' or username = '$e' inside my MySQL query.
Here is my MySQL query so far.
"SELECT user_id FROM users WHERE (email = '$e' AND pass=SHA1('$p'))"
If you want to modify you existing query so that it works even if $e matches username, you can do:
SELECT user_id
FROM users
WHERE (email = '$e' OR username = '$e') AND pass=SHA1('$p')