Advertisement
Guest User

Untitled

a guest
Jan 28th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. <?php
  2. chdir(dirname(__FILE__));
  3. include("../actions/dbvars.inc");
  4.  
  5. $timestart=time();
  6.  
  7. function microtime_float()
  8. {
  9. list($usec, $sec) = explode(" ", microtime());
  10. return ((float)$usec + (float)$sec);
  11. }
  12.  
  13.  
  14.  
  15. $gap=2*24*60*60;
  16. $oldtime=$timestart-$gap;
  17.  
  18. $nstart='2014-09-01 00:00:00';
  19. $nend='2014-09-30 23:59:59';
  20. $caveat_str='';
  21.  
  22. $groupid=0;
  23. $bdm_groupid=0;
  24. $supergroupid=20;
  25. $usertype=10;
  26. $suppid=0;
  27. $firstrun=1;
  28. $reptype=0;
  29. $now=time();
  30. $match_by_dept=0;
  31. $by_buyer=0;
  32. $buyid=0;
  33.  
  34. $qb="select DISTINCT group_to_retailer.f_rid, RETAILERS.RETAILER_NAME FROM group_to_retailer LEFT JOIN RETAILERS ON RETAILERS.RID=group_to_retailer.F_RID WHERE group_to_retailer.f_rtid in(select rtid from retailer_types where superid=$supergroupid)";
  35. $qb.=" order by RETAILER_NAME ASC";
  36.  
  37. $qbpass="select group_to_retailer.f_rid FROM group_to_retailer WHERE exists (select rtid from retailer_types where superid=$supergroupid and rtid=group_to_retailer.f_rtid)";
  38.  
  39. $qexist=$qbpass." and group_to_retailer.f_rid=compord.rid";
  40. $qexist2=$qbpass." and group_to_retailer.f_rid=retailers_to_suppliers.f_rid";
  41.  
  42.  
  43. $qo="select compord.id, compord.rid, compord.sid, sum(comporddet.invoice_value), sum(comporddet.discount_value), count(comporddet.id),compord.document_date, compord.doc_type, compord.invoice_no, rebate_master.rebate_percentage, supergroup_to_supplier.rebate_useprod, supergroup_to_supplier.rebate_method from compord left join comporddet on comporddet.compordid=compord.id and (comporddet.active='0' or comporddet.active is null) left join supergroup_to_supplier on supergroup_to_supplier.suppid=compord.sid and supergroup_to_supplier.supergroupid=$supergroupid left join rebate_master on rebate_master.sid=compord.sid and rebate_master.rid=compord.rid and rebate_master.supergroupid=$supergroupid where ";
  44.  
  45. if($buyid==0){
  46. $qo.=" exists ($qexist) ";
  47. }
  48. else{
  49. $qo.=" compord.rid=$buyid";
  50. }
  51.  
  52. $qo.=" and compord.doc_type='AINV'";
  53.  
  54. $qo.=" and (compord.supergroupid=0 or compord.supergroupid=$supergroupid)";
  55. $qo.=" and compord.active=0";
  56.  
  57. if($suppid!=0){
  58. $qo.=" and compord.sid='$suppid'";
  59. }
  60. else{
  61. $qo.=" and exists(select supergroup_to_supplier.suppid from supergroup_to_supplier where supergroupid=$supergroupid and active=0 and supergroup_to_supplier.suppid=compord.sid)";
  62. }
  63.  
  64. $qo.=$caveat_str;
  65.  
  66. $qo.=" AND compord.document_date between '$nstart' and '$nend'";
  67.  
  68. $qo.=" group by compord.id, compord.rid, compord.sid, compord.document_date, compord.doc_type, compord.invoice_no, rebate_master.rebate_percentage, supergroup_to_supplier.rebate_useprod, supergroup_to_supplier.rebate_method order by compord.id asc";
  69.  
  70. echo("<strong>Query : </strong>$qo");
  71.  
  72.  
  73. $time_start = microtime_float();
  74. $hostname='40.127.106.136';
  75. $myDB='bgate_system_main';
  76. $myUser='bgate_odbc';
  77. $myPass='s1m0nSAYS';
  78. $connectionInfo = array("Database"=>$myDB, "UID" => $myUser, "PWD" => $myPass);
  79.  
  80. $dsn = 'sqlsrv:server=40.127.106.136;database=bgate_system_main';
  81. $user = 'bgate_odbc';
  82. $password = 's1m0nSAYS';
  83.  
  84. try {
  85. $db = new PDO($dsn, $user, $password);
  86. } catch (PDOException $e) {
  87. echo '<br><br>PDO Connection failed: ' . $e->getMessage().'<br>';
  88. }
  89.  
  90. if(isset($db)){
  91. $ro=sqlsrv_query($qo, $db) or die($qo);
  92.  
  93. $time_end = microtime_float();
  94. $time = $time_end - $time_start;
  95.  
  96. $time=sprintf("%01.3f", $time);
  97. $now=time();
  98.  
  99. echo("<br><br><strong>SQLSRV - $time sec</strong><br>");
  100. }
  101.  
  102. $time_start = microtime_float();
  103.  
  104. $db=odbc_connect($dbnam,$usr,$pwd);
  105. $ro=odbc_exec($db,$qo) or die($qo);
  106.  
  107. $time_end = microtime_float();
  108. $time = $time_end - $time_start;
  109.  
  110. $time=sprintf("%01.3f", $time);
  111. $now=time();
  112.  
  113. echo("<br><strong>ODBC - $time sec</strong><br>");
  114.  
  115.  
  116.  
  117.  
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement