clickhouse php,php 链接 clickhouse

1 <?php

2 //var_dump(is_dir("./sjignen"));

3 //var_dump(file_exists(__DIR__."/day4.php"));

4 $basePath = "E:/php_project/sangfor_ready/";

5

6 function echo_all_path($pathName)

7 {

8 if (is_dir($pathName))

9 {

10

11 $handle = opendir($pathName);

12 while ($line = readdir($handle))

13 {

14 // echo "查找中";

15 // echo $line."\n";

16 if ($line!="." && $line !="..")

17 {

18 echo "当前是目录:".$pathName.$line."\n";

19 echo_all_path($pathName.$line."/");

20 }

21

22 }

23 closedir($handle);

24 }

25 else

26 {

27 echo "当前是文件:".$pathName."\n";

28 return;

29 }

30 }

31 //echo_all_path($basePath);

32

33 function display_all_path($path)

34 {

35 $handle = opendir($path);

36 while($line = readdir($handle))

37 {

38 echo $line."\n";

39 }

40 closedir($handle);

41 }

42 //$fd = fopen("./shiqi.txt","ab+");

43 //fwrite($fd,"shi qi shi wo !");

44 //fflush($fd);

45 //fclose($fd);

46 //$fd2 = fopen("./shiqi.txt","rb");

47 //$msg = fread($fd2,filesize("./shiqi.txt"));

48 //print_r(explode(" ", $msg));

49 //unlink("./shiqi.txt");

50 //display_all_path($basePath);

51 $db_host = "localhost";

52 $db_port = "3306";

53 $db_name= "test";

54 $charset = "utf8";//别带 - utf-8 不行

55 $user_name = "root";

56 $user_pwd = "1475651660";

57 $tb_name = 'netflow';

58

59 function zifll($param,$char='0')

60 {

61 if(!is_string($param))

62 {

63 $param = (string)$param;

64 }

65 if(strlen($param)<2)

66 {

67 $param = "0".$param;

68 }

69 else if(strlen($param)>2)

70 {

71 $param = substr($param,strlen($param)-2);

72 }

73 return $param;

74 }

75 $conn_obj = mysqli_connect($db_host,$user_name,$user_pwd,$db_name,$db_port);

76 $conn_obj->set_charset($charset);

77 $sql = "update {$tb_name} set record_time=";

78

79 //for ($i=2;$i<=26;$i++)

80 //{

81 // $month = zifll(mt_rand(1, 6));

82 // $day = zifll(mt_rand(1,28));

83 // $hour = zifll(mt_rand(1,24));

84 // $minutes = zifll(mt_rand(0,59));

85 // $sec = zifll(mt_rand(0,59));

86 // $excute_sql = $sql . "'2020-{$month}-{$day} {$hour}:{$minutes}:{$sec}' where id={$i};";

87 // echo $excute_sql,"\n";

88 //

89 //}

90

91 $param = array(

92 'time_range'=>"2020-05-03 00:00:00|2020-07-07 00:00:00",

93 'src_ip'=>"192.168.0.1",

94 'src_port'=>8080,

95 'dst_ip'=>'',

96 'dst_port'=>null,

97 'page'=>0

98 );

99

100 function get_query_sql($param)

101 {

102 $query_sql = "select * from test.netflow ";

103 if(empty($param)||!is_array($param))

104 {

105 echo "No paramter!";

106 exit();

107 }

108 $time_rage = explode("|",$param["time_range"]);

109 if($time_rage[0])

110 {

111 $query_sql .= "where ";

112 $query_sql .= "record_time > '{$time_rage[0]}' ";

113 }

114 if($time_rage[1])

115 {

116 $query_sql .= "and ";

117 $query_sql .= "record_time < '{$time_rage[1]}' ";

118 }

119 // array_splice($param,"time_range");

120 unset($param["time_range"]);

121 foreach($param as $key=>$value)

122 {

123 if(isset($param[$key]))

124 {

125 if ($key=="page"){

126 $offset = $value==0?"0":(string)$value*20;

127 $query_sql .= "limit 20 offset {$offset}";

128 }

129 else if($value)

130 {

131 $query_sql .= "and ";

132 if(is_string($value))

133 {

134 $query_sql .= "{$key} = '{$value}' ";

135 }

136 else

137 {

138 $query_sql .= "{$key} = {$value} ";

139 }

140 }

141

142

143 }

144 }

145 // $query_sql = $query_sql.trim();

146 $query_sql = trim($query_sql);

147 $query_sql .= ";";

148 return $query_sql;

149 }

150

151 $result = $conn_obj->query(get_query_sql($param));

152 echo json_encode($result->fetch_all(MYSQLI_ASSOC));

153 //var_dump(is_array($param));

154 ?>

标签:00,time,param,value,sql,query,php,链接,clickhouse

来源: https://www.cnblogs.com/shiqi17/p/12827926.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值