나는 단순히 \AsyncMysqlConnectionResult $connec;
객체의 AsyncMysqlQueryResult 객체
<?hh
namespace Connection;
require_once("ini.php");
/**
* Class for execute and fetch query
*/
class MyQuery
{
/**
* if connection isn't valid recreate pool
*/
private ?\AsyncMysqlConnectionPool $pool;
/**
* \AsyncMysqlConnection object, store $conn
*/
private \AsyncMysqlConnection $connec;
/**
* \AsyncMysqlQueryReturn object, store return query
*/
private \AsyncMysqlQueryResult $result;
/**
* check if $conn object isValid(), if not release
* connection
*/
public function __construct(\AsyncMysqlConnection $conn)
{
if ($conn->isValid() == false)
{
$this->pool = new MyPool();
$this->connec = $this->pool->connect();
}
else
$this->connec = $conn;
$this->result = object;
}
/**
* escape query and execute it
*/
public async function query(string $query): Awaitable<\AsyncMysqlQueryResult>
{
$query = $this->connec->escapeString($query);
echo "Query escape\n";
/* Try to execute the query, if fail display error */
try
{
$this->result = await $this->connec->query($query);
//log request with ini
}
catch (Exception $e)
{
echo "Couldn't execute the request, error with message :<br>";
var_dump($e->getMessage());
//log request with fail
}
echo "Query done succefully\n";
return $this->result;
}
/**
* escape Map array and execute the request
*/
public async function queryf(HH\FormatString<HH\SQLFormatter> $query, array<string> $params): Awaitable<\AsyncMysqlQueryResult>
{
$i = 0;
while ($params[$i++])
$params[$i] = $this->connec->escapeString($params[$i]);
/* Try to execute the query, if fail display error */
try
{
$result = await $this->connec->queryf($query, implode(', ', $params));
//log request with ini
}
catch (Exception $e)
{
echo "Couldn't execute the request, error with message :<br>";
var_dump($e->getMessage());
//log request with fail
}
echo "Query done succefully\n";
return $this->result;
}
}
newtype AsyncMysqlConnectionResult = object;
newtype FormatString<T> = string;
async function simple_query(\AsyncMysqlConnection $conn): Awaitable<Vector>
{
$connec = new MyQuery($conn);
$ret = await $connec->query('SELECT * FROM users');
return $ret->vectorRows();
}
function run_query(\AsyncMysqlConnection $conn): void
{
$r = \HH\Asio\join(simple_query($conn));
var_dump($r);
}
run_query ($의 CONN)를 초기화 원하는 초기화 할 수 없습니다;
이 객체를 사용하려면 https://docs.hhvm.com/hack/reference/class/AsyncMysqlConnectionPool/connect/ 클래스와 connect() 메소드를 사용하여 다음을 가져 오십시오. \ AsyncMysqlConnectionResult $ connec 객체.
나는이 변수 유형을 초기화 할 수있는 방법을 찾을 수없는, 내가 만들 하려고했습니다 newtype은 AsyncMysqlConnectionResult = 객체하지만 filechecker 나를 돌아 : Unbound name: Connection\object (an object type)
질문에 대한 답변이 아니지만 여기 문서에 몇 가지 예가 나와 있습니다. https://docs.hhvm.com/hack/async/examples#accessing-mysql –
감사합니다. 많은 것을 읽었습니다. hhvm 문서이지만이 페이지는 아닙니다. HH \ FormatString queryf 함수의 다른 형식으로 다른 문제에 붙어있어,이 함수에 문자열 형식을 보낼 수 없습니다. 왜 이런 complexe 형식이 ... 모르겠어요. –
bbichero
queryf 형식 문자열 자리 표시자를 정적으로 typechecked 수 있도록 리터럴 문자열이 필요합니다. 여기에 정보 : https://docs.hhvm.com/hack/reference/class/AsyncMysqlConnection/queryf/ –