class AsyncMysql{
public $dbSource = '';
public $dbConfig = '';
public function __construct(){
$this->dbSource = new Swoole\Mysql;
$this->dbConfig= [
'host'=>'127.0.0.1',
"port"=>3306,
"user"=>"root",
"password"=>"root",
"database"=>"test",
"charset"=>'utf8',
];
}
public function update(){
}
public function add(){
}
public function execute($id,$mark){
$this->dbSource->connect($this->dbConfig,function($db,$result){
echo 'mysql Connect'.PHP_EOL;
if($result === false){
var_dump($db->connect_error);
exit;
}
$sql = 'select * from test';
$db->query($sql,function($db,$result){
if($result ===false){
echo 'query false';
}elseif($result ===true){
echo 'query ok';
}else{
print_r($result);
}
$db->close();
});
});
return true;
}
}
$my = new AsyncMysql();
$res = $my->execute(1,1);
var_dump($res);
echo 'this is ok?';