This is the code that I use when using PDO SQL calls. This is part of a class, so everywhere you see “$this->” it’s setting a var in the class.
Where you see “if ( $sqlIsSelect )” is where I get the row count. For Selects, it sets the number of returned rows, but for Inserts, Updates, Deletes, it set the number of row affected. 
public function serverConnect() {
try {
$servername = DBS_SERVERNAME;
$serverport = DBS_SERVERPORT;
$username = DBS_USERNAME;
$password = DBS_PASSWORD;
$dbname = DBS_DBNAME;
$optDB = array(
\PDO::MYSQL_ATTR_FOUND_ROWS => TRUE,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
);
$newDB = new \PDO( "mysql:host=$servername;port=$serverport;dbname=$dbname", $username, $password, $optDB );
return $newDB;
} catch ( \PDOException $e ) {
logEventToFile( 'Catch', 'DBConnect', $e->getMessage(), paramEncode( $_SERVER[ 'PHP_SELF' ] ), $_SESSION[ 'recUsersCURRENT' ][ 'EmailAddress' ] ?? 'No', $_SESSION[ 'recUsersCURRENT' ][ UUIDUSERS ] ?? 'No' );
return 'Error: ' . $e->getMessage();
}
}
public function query( ) {
// Init
$this->errorB = false;
$this->rowsD = [];
$this->rowCount = 0;
$this->messageSQL = '';
$this->messageExtra = '';
try {
// Connect
if ( !isset( $GLOBALS[ 'db' ] ) ) {
$GLOBALS[ 'db' ] = $this->serverConnect();
}
// Prepared Statement
$ps = $GLOBALS[ 'db' ]->prepare( $this->querySQL );
// Bind
if ( !empty( $this->queryBindValuesA ) ) {
$bindValuesArrayCount = count( $this->queryBindValuesA );
for ( $bindIndex = 0; $bindIndex <= ( $bindValuesArrayCount - 1 ); $bindIndex++ ) {
$thisColValue = $this->queryBindValuesA[ $bindIndex ];
// Bind as NULL if value is 'NULL'
if ( strval( $thisColValue ) === 'NULL' ) {
$ps->bindValue( $bindIndex + 1, NULL, \PDO::PARAM_NULL );
} else {
$ps->bindValue( $bindIndex + 1, $thisColValue, \PDO::PARAM_STR );
}
}
}
// Execute
$ps->execute();
// Check the Statement
$sqlWords = explode( ' ', $this->querySQL );
$sqlIsSelect = ( strtoupper( $sqlWords[ 0 ] ) === 'SELECT' ? true : false );
// $sqlIsInsert = ( strtoupper( $sqlWords[ 0 ] ) === 'INSERT' ? true : false );
// $sqlIsUpdate = ( strtoupper( $sqlWords[ 0 ] ) === 'UPDATE' ? true : false );
// Process
if ( $sqlIsSelect ) {
// Process SELECT
$this->errorB = false;
$this->rowsD = $ps->fetchAll( \PDO::FETCH_ASSOC );
$this->rowCount = count( $this->rowsD );
} else {
// Process NOT SELECT
$this->errorB = false;
$this->rowsD = [];
$this->rowCount = $ps->rowCount();
}
} catch ( \PDOException $e ) {
// Log Error
logEventToFile( 'Catch', 'DBSelect: ' . $this->querySQL, $e->getMessage(), paramEncode( $_SERVER[ 'PHP_SELF' ] ), $_SESSION[ 'recUsersCURRENT' ][ 'EmailAddress' ] ?? 'No', $_SESSION[ 'recUsersCURRENT' ][ UUIDUSERS ] ?? 'No' );
$this->errorB = true;
$this->rowsD = [];
$this->rowCount = 0;
$this->messageSQL = $e->getMessage();
return;
}
// Update Message
if ( $this->rowCount < 1 ){
$this->messageSQL = 'Found 0';
} else {
$this->messageSQL = 'Found ' . $this->rowCount;
}
}