<?php


namespace App\Traits;


trait Server6UssdDatabase
{

    /**
     * Establishes connection to the live database where the service can be published to for the ussd to take effect
     * @return false|\mysqli
     */
    public function ussdLiveDBConnection()
    {
        return mysqli_connect('95.216.10.33', "icet", "kutamidFzp2iii9oi@9i", 'ussd', '3327');
//        return mysqli_connect('95.216.10.33', "stealBars_of_Jerico", "H3dFzp2DSa9S@9i", 'ussd', '3327');
    }

    /**
     * Extract ussd service code extension. ie *899*45# returns 45.
     * @param $code
     * @return mixed
     */
    public function extractExtensionFromServiceCode($code)
    {
        //split the code on #, ie *899*45# will become *899*45
        $extensionPart = explode('#', $code);
        //split the extension part on * and the extension ie 45 will be in the 2nd index
        return explode('*', $extensionPart[0])[2];
    }
}
