<?php
function msql_query($sql,$link='')
{
     $sql=str_replace('now()','date_add(now(),interval 1 hour)',$sql);
     
     if(empty($link)){return;}
     
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$res=mysql_query($sql,$link);}
     if($ver>=7){$res=mysqli_query($link,$sql);}
     return $res;
}  

function msql_result($res,$row,$col=0)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){if(mysql_num_rows($res)>0){$val=mysql_result($res,$row,$col);}}
     if($ver>=7)
     {
          if(mysqli_num_rows($res)>0){$res->data_seek($row); $datarow=$res->fetch_array(); $val=$datarow[$col];}
          if($col=='type')
          {if(mysqli_num_rows($res)>0){mysqli_data_seek($res,$row); $datarow=mysqli_fetch_array($res); $val=$datarow[1];}}
     }
     return $val;
}

function msql_data_seek(&$res,$row=0)
{
     $ver=substr(phpversion(),0,1);
     if($ver<=5){mysql_data_seek($res,$row);}
     if($ver>=7){mysqli_data_seek($res,$row);}
     return $res;
}

function msql_num_fields($res)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_num_fields($res);}
     if($ver>=7){$val=mysqli_num_fields($res);}
     return $val;
}

function msql_affected_rows($res)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_affected_rows($res);}
     if($ver>=7){$val=mysqli_affected_rows($res);}
     return $val;
}

function msql_num_rows($res)
{
     if(empty($res)){return 0;}
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_num_rows($res);}
     if($ver>=7){$val=mysqli_num_rows($res);}
     return $val;
}

function msql_fetch_assoc($res)
{
     $val='';
     if(empty($res)){return $val;}
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_fetch_assoc($res);}
     if($ver>=7){$val=mysqli_fetch_assoc($res);}
     return $val;
}

function msql_fetch_array($res)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_fetch_array($res);}
     if($ver>=7){$val=mysqli_fetch_array($res);}
     return $val;
}

function msql_field_name($res,$idx=0)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_field_name($res,$idx);}
     if($ver>=7)
     {
          $properties = mysqli_fetch_field_direct($res, $idx);
          $val=is_object($properties) ? $properties->name : null;
     }
     return $val;
}

function msql_field_type($res,$idx=0)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_field_type($res,$idx);}
     if($ver>=7)
     {
          $table_info = mysqli_fetch_field_direct($res, $idx);
          $val=$table_info->type;
     }
     return $val;
}

function msql_insert_id($link)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_insert_id($link);}
     if($ver>=7){$val=mysqli_insert_id($link);}
     return $val;
}

function msql_errno($link)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_errno($link);}
     if($ver>=7){$val=mysqli_errno($link);}
     return $val;
}

function msql_error($link)
{
     $val='';
     $ver=substr(phpversion(),0,1);
     if($ver<=5){$val=mysql_error($link);}
     if($ver>=7){$val=mysqli_error($link);}
     return $val;
}




?>