no message
parent
01ceafe255
commit
267b65fbbb
@ -0,0 +1,3 @@
|
||||
.idea
|
||||
.DS_Store
|
||||
config.ini
|
||||
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Workerman\Lib;
|
||||
use Workerman\Worker;
|
||||
|
||||
$bot_loop = new Worker();
|
||||
$bot_loop->count = 1;
|
||||
$bot_loop->name = "LuCodePhpBot";
|
||||
|
||||
function BotFunc()
|
||||
{
|
||||
$db = Db::get();
|
||||
$info = $db->getRow('select * from admin where id = 1');
|
||||
var_dump($info);
|
||||
}
|
||||
|
||||
$bot_loop->onWorkerStart = function () {
|
||||
Timer::add(2, function () {
|
||||
BotFunc();
|
||||
});
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Workerman\Worker;
|
||||
use \Workerman\Lib\Timer;
|
||||
use \Workerman\Lib\Tool;
|
||||
|
||||
$bot_loop = new Worker();
|
||||
$bot_loop->count = 1;
|
||||
$bot_loop->name = "2秒后自动触发";
|
||||
|
||||
function BotFunc()
|
||||
{
|
||||
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
|
||||
var_dump($res);
|
||||
}
|
||||
|
||||
$bot_loop->onWorkerStart = function () {
|
||||
BotFunc();
|
||||
Timer::add(2, function () {
|
||||
BotFunc();
|
||||
});
|
||||
};
|
||||
@ -0,0 +1,6 @@
|
||||
AppName = 鹿和开发套件
|
||||
|
||||
MainDbName = example
|
||||
MainDbUser = example
|
||||
MainDbPassword = example
|
||||
MainDbHost = example.com:3306
|
||||
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Workerman\Worker;
|
||||
use \Workerman\Lib\Timer;
|
||||
use \Workerman\Lib\Tool;
|
||||
|
||||
$bot_loop = new Worker();
|
||||
$bot_loop->count = 1;
|
||||
$bot_loop->name = "每10秒自动触发";
|
||||
$loop = 10;
|
||||
$time = time() - $loop;
|
||||
function BotFunc($loop, &$time)
|
||||
{
|
||||
if (time() - $time >= $loop) {
|
||||
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
|
||||
var_dump($res);
|
||||
$time = $time + $loop;
|
||||
}
|
||||
}
|
||||
|
||||
$bot_loop->onWorkerStart = function () use ($loop, &$time) {
|
||||
BotFunc($loop, $time);
|
||||
Timer::add(2, function () use ($loop, &$time) {
|
||||
BotFunc($loop, $time);
|
||||
});
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Workerman\Worker;
|
||||
use \Workerman\Lib\Timer;
|
||||
use \Workerman\Lib\Tool;
|
||||
|
||||
$bot_loop = new Worker();
|
||||
$bot_loop->count = 1;
|
||||
$bot_loop->name = "2秒后自动触发";
|
||||
|
||||
function BotFunc()
|
||||
{
|
||||
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
|
||||
var_dump($res);
|
||||
}
|
||||
|
||||
$bot_loop->onWorkerStart = function () {
|
||||
BotFunc();
|
||||
Timer::add(2, function () {
|
||||
BotFunc();
|
||||
});
|
||||
};
|
||||
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Workerman\Worker;
|
||||
use \Workerman\Lib\Timer;
|
||||
use \Workerman\Lib\Tool;
|
||||
|
||||
$bot_loop = new Worker();
|
||||
$bot_loop->count = 1;
|
||||
$bot_loop->name = "到达规定时间自动触发";
|
||||
$loop = 10;
|
||||
$time = strtotime(date('Y-m-d') . ' 20:21:00');
|
||||
function BotFunc($loop, &$time)
|
||||
{
|
||||
if (time() - $time >= 0) {
|
||||
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
|
||||
var_dump($res);
|
||||
$time = $time + $loop;
|
||||
}
|
||||
}
|
||||
|
||||
$bot_loop->onWorkerStart = function () use ($loop, &$time) {
|
||||
BotFunc($loop, $time);
|
||||
Timer::add(2, function () use ($loop, &$time) {
|
||||
BotFunc($loop, $time);
|
||||
});
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
256086
|
||||
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace Workerman\Lib;
|
||||
class Db
|
||||
{
|
||||
|
||||
public $db;
|
||||
private static $instance = array();
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$dsn = "mysql:dbname=" . $data['dbname'] . ";host=" . $data['dbhost'];
|
||||
$this->db = new \PDO($dsn, $data['dbuser'], $data['dbpassword']);
|
||||
$this->db->query('set character set utf8mb4;');
|
||||
$this->db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||
}
|
||||
|
||||
public static function get($key = 'Main'): Db
|
||||
{
|
||||
$database['dbname'] = Tool::ini($key . 'DbName');
|
||||
$database['dbuser'] = Tool::ini($key . 'DbUser');
|
||||
$database['dbpassword'] = Tool::ini($key . 'DbPassword');
|
||||
$database['dbhost'] = Tool::ini($key . 'DbHost');
|
||||
if (!isset(self::$instance[$database['dbname']]) || !self::$instance[$database['dbname']] instanceof self) {
|
||||
self::$instance[$database['dbname']] = new Db($database);
|
||||
} else {
|
||||
try {
|
||||
//断线重连
|
||||
self::$instance[$database['dbname']]->db->getAttribute(\PDO::ATTR_SERVER_INFO);
|
||||
} catch (\PDOException $e) {
|
||||
if (strpos($e->getMessage(), 'MySQL server has gone away') !== false) {
|
||||
self::$instance[$database['dbname']] = new Db($database);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self::$instance[$database['dbname']];
|
||||
}
|
||||
|
||||
|
||||
/*********PDO**********/
|
||||
public function count($sql, $parameters = null): int
|
||||
{
|
||||
return $this->exeupdate($sql, $parameters);
|
||||
}
|
||||
|
||||
public function querysql($sql, $parameters = null)
|
||||
{
|
||||
return $this->exeupdate($sql, $parameters);
|
||||
}
|
||||
|
||||
|
||||
public function querysqlinsertid($sql, $parameters = null)
|
||||
{
|
||||
if ($this->exeupdate($sql, $parameters)) {
|
||||
return $this->db->lastInsertId();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getRow($sql, $parameters = null)
|
||||
{
|
||||
$res = $this->exequery($sql, $parameters);
|
||||
if (count($res) > 0) {
|
||||
|
||||
return $res[0];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll($sql, $parameters = null)
|
||||
{
|
||||
$res = $this->exequery($sql, $parameters);
|
||||
if (count($res) > 0) {
|
||||
return $res;
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
public function beginTransaction()
|
||||
{
|
||||
$this->db->beginTransaction();
|
||||
}
|
||||
|
||||
public function rollback()
|
||||
{
|
||||
$this->db->rollback();
|
||||
}
|
||||
|
||||
public function commit()
|
||||
{
|
||||
$this->db->commit();
|
||||
}
|
||||
|
||||
public function exequery($sql, $parameters = null)
|
||||
{
|
||||
$conn = $this->db;
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($parameters);
|
||||
$rs = $stmt->fetchall(\PDO::FETCH_ASSOC);
|
||||
$stmt = null;
|
||||
$conn = null;
|
||||
return $rs;
|
||||
}
|
||||
|
||||
public function exeupdate($sql, $parameters = null)
|
||||
{
|
||||
$stmt = $this->db->prepare($sql);
|
||||
$stmt->execute($parameters);
|
||||
$affectedrows = $stmt->rowcount();
|
||||
$stmt = null;
|
||||
$conn = null;
|
||||
return $affectedrows;
|
||||
}
|
||||
|
||||
public function checklink()
|
||||
{
|
||||
$res = $this->db->getAttribute(\PDO::ATTR_SERVER_INFO);
|
||||
if (strpos($res, 'server has gone away') !== false) {
|
||||
$this->db = null;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function getinsertid()
|
||||
{
|
||||
return $this->db->lastInsertId();
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
return $this->db = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Workerman\Lib;
|
||||
class Db2
|
||||
{
|
||||
public static function i($db, $table, $array)
|
||||
{
|
||||
$insertArr = array();
|
||||
$sql = "insert into `{$table}`(";
|
||||
$sql1 = 'values(';
|
||||
foreach ($array as $key => $value) {
|
||||
$sql .= "`{$key}`,";
|
||||
$sql1 .= "?,";
|
||||
$insertArr[] = $value;
|
||||
}
|
||||
$sql = trim($sql, ',');
|
||||
$sql1 = trim($sql1, ',');
|
||||
$sql .= ")" . $sql1 . ")";
|
||||
$db->querysql($sql, $insertArr);
|
||||
return $db->getinsertid();
|
||||
}
|
||||
|
||||
public static function u($db, $table, $array, $where, $where_a = [])
|
||||
{
|
||||
$updateArr = array();
|
||||
$sql = "update `{$table}` set ";
|
||||
foreach ($array as $key => $value) {
|
||||
$sql .= "`{$key}`=?,";
|
||||
$updateArr[] = $value;
|
||||
}
|
||||
$sql = trim($sql, ',');
|
||||
$where = ' ' . $where;
|
||||
$sql .= $where;
|
||||
$updateArr = array_merge($updateArr, $where_a);
|
||||
return $db->querysql($sql, $updateArr);
|
||||
}
|
||||
|
||||
public static function d($db, $table, $where, $where_a = [])
|
||||
{
|
||||
$sql = "delete from `{$table}` " . $where;
|
||||
$db->querysql($sql, $where_a);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue