Avatar of Alex Lord
Alex Lord
 asked on

Going from old SQl to pdo, num rows alternative

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
PHPSQL* PDO

Avatar of undefined
Last Comment
Chris Stanyon

8/22/2022 - Mon
Ryan Chong

try:

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

Open in new window


PDOStatement::rowCount
http://php.net/manual/en/pdostatement.rowcount.php
ASKER CERTIFIED SOLUTION
Chris Stanyon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61