Jump to content

Recommended Posts

HI peeps,

 

Stumped with this one...

 

Have this query

<?php
$qry	=	"
SELECT
`messages`.`message_id` AS `messageID` ,
`users`.`username` AS `from` ,
`textsmall`.`text` AS `subject` ,
DATE_FORMAT(`messages`.`date` , '%W the %D of %M %Y at %l:%i %p') AS `messageDate` ,
`textfull`.`text` AS `message` ,
`messages`.`status` AS `status`
FROM
`messages`
LEFT JOIN
`textsmall`
ON
`textsmall`.`text_id`	=	`messages`.`subject`
LEFT JOIN
`textfull`
ON
`textfull`.`text_id`	=	`messages`.`text`
LEFT JOIN
`users`
ON
`users`.`user_id` = `messages`.`from`
WHERE
`messages`.`message_id` = :mssgID
AND
0 =
(
IF(
	`messages`.`to` = :userID ,
	`messages`.`status` & :toDelete ,
	`messages`.`status` & :fromDelete
)
)
AND
(
`messages`.`to` = :userID
OR
`messages`.`from` = :userID
)
			";
echo 'Mssg: ' . $mssgID . ' User: ' . $_SESSION['user_id'] . ' ToDel: ' . TO_DELETE . ' FromDel: ' . FROM_DELETE;
$mssg	=	$this->prepare ( $qry );
$mssg->bindValue ( ':mssgID' , $mssgID , PDO::PARAM_INT );
$mssg->bindValue ( ':userID' , $_SESSION['user_id'] , PDO::PARAM_INT );
$mssg->bindValue ( ':toDelete' , TO_DELETE , PDO::PARAM_INT );
$mssg->bindValue ( ':fromDelete' , FROM_DELETE , PDO::PARAM_INT );
$mssg->execute ();
$arr	=	$mssg->fetchAll ( PDO::FETCH_ASSOC );

if	(
count ( $arr ) == 1
)
{
return $arr;
}
?>

 

this runs in a method (hence the return)...

 

Now this works fine on dev box AND when run through phpmyadmin on the live box but NOT when run through code.

 

Is there anything anyone can suggest as to why this could be so?

 

Any help much appreciated...

Link to comment
https://forums.phpfreaks.com/topic/183479-pdo-query-not-working-on-live-box/
Share on other sites

Update on this...

 

If I remove the conditional

AND

0 =

(

IF(

`messages`.`to` = :userID ,

`messages`.`status` & :toDelete ,

`messages`.`status` & :fromDelete

)

)

 

the query runs sucessfuly...

 

Can anyone suggest why running the query through code with the offending portion of the query kept in?

That is the query run - the Values bound are:

 

mssgID ( the message id ) = 1 - this message exists.

userID = 1,

toDelete = 4

fromDelete = 8.

 

the status on message one is 3 so the bitwise comparison should return 0 hence the the message SHOULD be selected.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.