We help IT Professionals succeed at work.

Going from old SQl to pdo,  num rows alternative

Alex Lord
Alex Lord asked
on
102 Views
Last Modified: 2018-08-24
So i am converting this old outdated sql to pdo.


$query2 = "
								SELECT
									DISTINCT ev.EVENT AS EVENT
								FROM TXT2GIVE_EMAIL_EVENT$emailTableNum ev
								WHERE ev.CHARITY_ID='$charityId' AND ev.CAMPAIGN_ID='$campaignId' AND ev.EMAIL_SAVE_ID='$saveId' AND ev.EMAIL_ADDRESS='$email' AND ev.EMAIL_SAVE_ID IN (SELECT EMAIL_SAVE_ID FROM TXT2GIVE_EMAIL_SENT WHERE ev.CHARITY_ID='$charityId')
								ORDER BY TIMESTAMP ASC";
							$result2=mysql_query($query2, $db) or die(mysql_error());
							if(mysql_num_rows($result2))
							{

Open in new window



to pdo -

$stmt = new Database();

					$query = "SELECT
					DISTINCT ev.EVENT AS EVENT
						FROM TXT2GIVE_EMAIL_EVENT$emailTableNum ev
						WHERE ev.CHARITY_ID = :clientID AND ev.CAMPAIGN_ID = :campaignID AND ev.EMAIL_SAVE_ID = :saveID AND ev.EMAIL_ADDRESS = :email AND ev.EMAIL_SAVE_ID IN (SELECT EMAIL_SAVE_ID FROM TXT2GIVE_EMAIL_SENT WHERE ev.CHARITY_ID = :clientID)
						ORDER BY TIMESTAMP ASC";

					$stmt->query( $query );
					$stmt->bind( ':clientID', $clientId );
					$stmt->bind( ':campaignID', $campaignId );
					$stmt->bind( ':saveID', $saveId );
					$stmt->bind( ':email', $email );
					$stmt->execute();
					$result = $stmt->all();

Open in new window



What is my alternative for  this line
if(mysql_num_rows($result2))

Open in new window


i need to be able to do the same with pdo get the number of rows to perform this statement
Comment
Watch Question

CERTIFIED EXPERT

Commented:
try:

if ($stmt->rowCount() > 0) {
   //... got record, do your stuffs
}

Open in new window


PDOStatement::rowCount
http://php.net/manual/en/pdostatement.rowcount.php
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.