<?php
    
abstract class Test
    
{
        protected 
$con;
        protected 
$db_host      'remote-host';
        protected 
$db_user      'test';
        protected 
$db_ssluser   'testssl';
        protected 
$db_pass      'benchmark';
        protected 
$db_base      'test';
        protected 
$ssl;
        protected 
$test;
        public abstract function 
init();
        public abstract function 
execute();
        public abstract function 
finalize();
        public abstract function 
get_test_name();

        public function  
__construct($ssl$test) {
            
$this->ssl $ssl;
            
$this->test $test;
        }
    }

    class 
test_mysql extends Test
    
{
        public function 
init() {
            if(
$this->ssl) {
                
$this->con mysql_connect($this->db_host$this->db_ssluser$this->db_passnull,  MYSQL_CLIENT_SSL) or die("Connection error");
            } else {
                
$this->con mysql_connect($this->db_host$this->db_user$this->db_pass) or die("Connection error");
            }
            
mysql_select_db($this->db_base$this->con) or die("Db selection error ");
        }

        public function 
execute() {
            switch(
$this->test)
            {
                case 
1:
                    
$res mysql_query("INSERT INTO benchmark VALUES (374943, 394.034, 'dummydummy', NOW())"$this->con) or die("Query error");
                    break;
                case 
2:
                    
$res mysql_query("SELECT *, NOW() FROM benchmark LIMIT 0, 100"$this->con) or die("Query error");
                    while(
$row mysql_fetch_row($res));
                    break;
                case 
3:
                    
$res mysql_query("SELECT *, NOW() FROM benchmark LIMIT 0, 10"$this->con) or die("Query error");
                    while(
$row mysql_fetch_row($res));
                    break;
            }
        }

        public function 
finalize() {
            
mysql_close($this->con);
        }

        public function 
get_test_name() {
            return 
"MySQL Connection using MySQL library SSL=".($this->ssl 'on' 'off');
        }
    }

    class 
test_mysqli extends Test
    
{
        private 
$ssl_ca '/dev/null';
        private 
$ssl_cert '';
        private 
$ssl_key '';

        public function 
init() {
            
$this->con mysqli_init();
            if(
$this->ssl) {
                
$this->con->ssl_set($this->ssl_key$this->ssl_cert$this->ssl_canullnull) or die("SSL Configuration error");
                
$this->con->real_connect($this->db_host$this->db_ssluser$this->db_pass$this->db_base) or die("Connection error");
            } else {
                
$this->con->real_connect($this->db_host$this->db_user$this->db_pass$this->db_base) or die("Connection error");
            }
        }

        public function 
execute() {
            switch(
$this->test)
            {
                case 
1:
                    
$res $this->con->query("INSERT INTO benchmark VALUES (374943, 394.034, 'dummydummy', NOW())") or die("Query error".$this->con->error);
                    break;
                case 
2:
                    
$res $this->con->query("SELECT *, NOW() FROM benchmark LIMIT 0, 100") or die("Query error".$this->con->error);
                    while(
$row $res->fetch_row());
                    break;
                case 
3:
                    
$res $this->con->query("SELECT *, NOW() FROM benchmark LIMIT 0, 10") or die("Query error".$this->con->error);
                    while(
$row $res->fetch_row());
                    break;
            }
        }

        public function 
finalize() {
            
$this->con->close();
        }

        public function 
get_test_name() {
            return 
"MySQL Connection using MySQLi new library SSL=".($this->ssl 'on' 'off');
        }
    }
?>