src/MysqliLib.php
public static function fetchPrimaryKey(\mysqli $mysqliConn, string $tableName) : array
    {
        $primaryKeyArray = array();
        
        $query = "show index FROM `" . $tableName . "`";
        /*@var $result mysqli_result */
        $result = $mysqliConn->query($query);
        
        if ($result === FALSE)
        {
            throw new \Exception("Failed to fetch primary key", 500);
        }
        
        while (($row = $result->fetch_assoc()) != null)
        {
            if ($row["Key_name"] === "PRIMARY")
            {
                $primaryKeyArray[] = $row["Column_name"];
            }
        }
        
        if (count($primaryKeyArray) == 0)
        {
            throw new \Exception($tableName . " does not have a primary key.");
        }
        
        return $primaryKeyArray;
    }
public static function fetchPrimaryKey(\mysqli $mysqliConn, string $tableName) : array
    {
        $primaryKeyArray = array();
        
        $query = "show index FROM `" . $tableName . "`";
        /*@var $result mysqli_result */
        $result = $mysqliConn->query($query);
        
        if ($result === FALSE)
        {
            throw new \Exception("Failed to fetch primary key", 500);
        }
        
        while (($row = $result->fetch_assoc()) != null)
        {
            if ($row["Key_name"] === "PRIMARY")
            {
                $primaryKeyArray[] = $row["Column_name"];
            }
        }
        
        if (count($primaryKeyArray) == 0)
        {
            throw new \Exception($tableName . " does not have a primary key.");
        }
        
        return $primaryKeyArray;
    }
public static function fetchPrimaryKey ( \ mysqli $ mysqliConn , string $ tableName ) : array { $ primaryKeyArray = array ( ) ; $ query = "show index FROM `" . $ tableName . "`" ; /*@var $result mysqli_result */ $ result = $ mysqliConn -> query ( $ query ) ; if ( $ result === FALSE ) { throw new \ Exception ( "Failed to fetch primary key" , 500 ) ; } while ( ( $ row = $ result -> fetch_assoc ( ) ) != null ) { if ( $ row [ "Key_name" ] === "PRIMARY" ) { $ primaryKeyArray [ ] = $ row [ "Column_name" ] ; } } if ( count ( $ primaryKeyArray ) == 0 ) { throw new \ Exception ( $ tableName . " does not have a primary key." ) ; } return $ primaryKeyArray ; }
Dynamically discovers the primary key for this table and sets this objects member variable
accordingly. This returns an array
@param \mysqli $mysqliConn - the mysqli connection to get primary key through.
@param string $tableName - the name of the table to fetch the primary key for.
@return array - the column names that act as the primary key because it could be
a combined key.
@throws Exception
Dynamically discovers the primary key for this table and sets this objects member variable accordingly . This returns an array