"PHP" / Говнокод #21164 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
$__sys=array();
{//bd 
$__sys['bd']=array(
  'c'=>new PDO('mysql:host=host;dbname=dbname;charset=utf8', 'username', 'pass'),
  'd_new'=>array(),
  //'d_bd'=>array(),
  'execute'=>'',
  
);
function bd_get_arrays($what='*',$table,$where=false,$where2=false,$order_by=false,$start=false,$limit=false){
  $s_act=false;
  if($what=='-only_ids'){$s_act='only_ids';$what='*';}
  $q=is_object($where)?$where:$GLOBALS['__sys']['bd']['c']->prepare('SELECT '.$what.' FROM '.$table.' WHERE '.($where?$where:'1').
    ($order_by?' order by '.$order_by:'').($start?' limit '.$start.($limit?', '.$limit:''):''));
  $q->execute($where2&&is_array($where2)?$where2:null);
  $w=$q->fetchAll();
  if($what=='*'){
    $I=count($w);
    if(!isset($GLOBALS['__sys']['bd']['d_new'][$table]))$GLOBALS['__sys']['bd']['d_new'][$table]=array();
    //if(!isset($GLOBALS['__sys']['bd']['d_new'][$table]))$GLOBALS['__sys']['bd']['d_bd'][$table]=array();
    for($i=0;$i<$I;$i++){
      $GLOBALS['__sys']['bd']['d_new'][$table][$w[$i]['id']]=$w[$i];
      //$GLOBALS['__sys']['bd']['d_bd'][$table][$w[$i]['id']]=$w[$i];
    }
  }
  if($s_act=='only_ids'){
    $r=array();
    $I=count($w);
    for($i=0;$i<$I;$i++){
      $r[]=$w[$i]['id'];
      //$GLOBALS['__sys']['bd']['d_bd'][$table][$w[$i]['id']]=$w[$i];
    }
  }
  return $w;
}
function bd_get_array($what='*',$table,$where=false,$where2=false,$order_by=false){
  if(is_numeric($where)){
    if(isset($GLOBALS['__sys']['bd']['d_new'][$table],$GLOBALS['__sys']['bd']['d_new'][$table][$where]))
      return $GLOBALS['__sys']['bd']['d_new'][$table][$where]; else $where='id='.$where;
  }
  $q=bd_get_arrays($what='*',$table,$where,$where2,$order_by,1);
  return isset($q[0])?$q[0]:false;
}
function bd_set_array($table,$set=false,$where=false,$where2=false,$order_by=false,$start=false,$limit=false){
  if(!$set&&is_array($set)&&!empty($set))return;
  if(!isset($GLOBALS['__sys']['bd']['d_new'][$table])&&$where)
    bd_get_arrays('*',$table,$where,$where2,$order_by,$start,$limit);
  if($where){bd_get_arrays('-only_ids',$table,$where,$where2);
  }else{$w=array_keys($GLOBALS['__sys']['bd']['d_new'][$table]);$I=count($w);}
  $GLOBALS['__sys']['bd']['execute'].='UPDATE `game_marsgame_users` SET ';
  for($i=0;$i<$I;$i++){
    $r=array_keys($set);
    $R=count($r);
    for($ri=0;$ri<$R;$ri++){
      $GLOBALS['__sys']['bd']['d_new'][$table][$w[$i]][$r[$ri]]=$set[$r[$ri]];
      $GLOBALS['__sys']['bd']['execute'].=$r[$ri].'="'.addslashes($set[$r[$ri]]).'"';
    }
  }
  $GLOBALS['__sys']['bd']['execute'].=' WHERE id in('.implode(',',$w).');';
  return;
}
function bd_query($sql){
  $GLOBALS['__sys']['bd']['c']->query($sql);
}
function bd_close(){
  $GLOBALS['__sys']['bd']['c']->query($GLOBALS['__sys']['bd']['execute']);
}
}

сорс https://toster.ru/q/352637

Запостил: riot26 riot26, (Updated )

Комментарии (15) RSS

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8