Rowcount解决方案,带有fetch_field_direct(),getColumnMeta(); PHP 7的可移植性?

I'm rewriting an application so that it may use MYSQLI or PDO queries, controllable by a $connection_type variable that holds either 'mysqli' or 'pdo' as a flag as to which is being used.

There are many queries in the existing code that require a rowcount of a given query. Obtaining the actual number of rows returned by a query has been questioned and answered in different ways elsewhere on Stackoverflow, but I think I've hit on an iron-clad method that will work with either MYSQLI or PDO, and then will work when the result object is from queries with variations on any of these forms (notice the third example; I've devised the function to work whether or not COUNT() is used in the query):

select count(*) from table
select count(distinct column) from table
select column1, column2, column3 from table

For MYSQLI, my solution relies on fetch_field_direct(), which is apparently set-in-stone and reliable. For PDO, however, my solution relies on the corresponding function, getColumnMeta(), which is flagged this way in the PHP.NET documentation:

Warning This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk.

So, I have two questions:

1) Can anyone see something I've overlooked in this method?

2) Does anyone know if getColumnMeta() is (a) present in the upcoming PHP 7 and then (b) if it has been finalized and what it returns and by what operators? If the name of the function is going to be the same and if it will return the "name" column as below, then my code--which is running fine on PHP 5.6.12--should therefore work on PHP 7 when it is released.

So, here is the current state of my function, which is working fine for the types of queries listed above both for MYSQLI and PDO (but have I overlooked something?):

function returnRowcount($result_object, $connection_type){
    if ($connection_type == 'mysqli') {
        $name_field = strtoupper($result_object->fetch_field_direct(0)->name);
        if (substr($name_field, 0, 6) == "COUNT(") {
            $row = $result_object->fetch_row();
            return $row[0];
        } else {
            return mysqli_num_rows($result_object);
        }       
    } elseif ($connection_type == 'pdo') {
        // WARNING: THE PHP DOCUMENTATION STATES THAT getColumnMeta MAY CHANGE IN FUTURE:
        $name_field = strtoupper($result_object->getColumnMeta(0)["name"]);
        if (substr($name_field, 0, 6) == "COUNT(") {
            return $result_object->fetchColumn();
        } else {
            return $result_object->rowcount();
        }
    }
}

There are many queries in the existing code that require a rowcount of a given query.

This is what is actually wrong in your application and have to be fixed instead.

In every place where returned rowcount is used, it is used not on purpose, to tell how may rows exactly has been returned, but only to tell if any row has been found at all. Which makes such a call extremely superfluous, as you have the data itself to tell if any data has been returned.

Regarding particular function in the OP, a function, that returns anything but 1 from the count(*) query makes absolutely no sense. Such ambiguous functions are awfully dangerous, and always lead to regrettable consequences. DO NOT obfuscate your own code.

function returnRowcount($result_object, $connection_type){
    if ($connection_type == 'mysqli') {
        return mysqli_num_rows($result_object);
    } elseif ($connection_type == 'pdo') {
        return $result_object->rowcount();
    }
}

is the only form it should be allowed to exist.

Note that there is nothing wrong with rowCount() method. Don't be an easy prey for old superstitions.

Nevertheless, as I noted before, there is extremely little use for such a function in web-development. You either select data (which you can count in PHP) or count (which you have just to fetch) but not both.