本文整理匯總了PHP中Doctrine\DBAL\Connection::fetchAssoc方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::fetchAssoc方法的具體用法?PHP Connection::fetchAssoc怎麽用?PHP Connection::fetchAssoc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::fetchAssoc方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fetchByRoot
public static function fetchByRoot(Connection $conn, $id, MembershipEntityInterface $root)
{
if ($root instanceof Area) {
$data = $conn->fetchAssoc('SELECT * FROM `' . EdkTables::MESSAGE_TBL . '` WHERE `id` = :id AND `areaId` = :rootId', [':id' => $id, ':rootId' => $root->getId()]);
} elseif ($root instanceof Group) {
$data = $conn->fetchAssoc('SELECT m.* FROM `' . EdkTables::MESSAGE_TBL . '` m ' . 'INNER JOIN `' . CoreTables::AREA_TBL . '` a ON a.`id` = m.`areaId` ' . 'WHERE m.`id` = :id AND a.`groupId` = :rootId', [':id' => $id, ':rootId' => $root->getId()]);
} elseif ($root instanceof Project) {
$data = $conn->fetchAssoc('SELECT m.* FROM `' . EdkTables::MESSAGE_TBL . '` m ' . 'INNER JOIN `' . CoreTables::AREA_TBL . '` a ON a.`id` = m.`areaId` ' . 'WHERE m.`id` = :id AND a.`projectId` = :rootId', [':id' => $id, ':rootId' => $root->getId()]);
}
if (false === $data) {
return false;
}
$item = self::fromArray($data);
if ($root instanceof Area) {
$item->area = $root;
} elseif ($root instanceof Group) {
$item->area = Area::fetchByGroup($conn, $data['areaId'], $root);
} elseif ($root instanceof Project) {
$item->area = Area::fetchByProject($conn, $data['areaId'], $root);
}
if (!empty($data['responderId'])) {
$item->responder = User::fetchByCriteria($conn, QueryClause::clause('u.id = :id', ':id', $data['responderId']));
}
return $item;
}
示例2: __call
/**
* Dispatches magic methods (findBy[Property]())
*
* @param string $methodName The name of the magic method
* @param string $arguments The arguments of the magic method
* @throws \Exception
* @return mixed
* @api
*/
public function __call($methodName, $arguments)
{
if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) {
$propertyName = lcfirst(substr($methodName, 6));
$sql = "select * from " . $this->tableName . " where " . $propertyName . " = :propertyValue order by id desc";
$result = $this->db->fetchAll($sql, array('propertyValue' => $arguments[0]));
// Convert query result to an array of objects
$objectList = array();
foreach ($result as $row) {
$id = $row['id'];
$objectList[$id] = $this->buildDomainObject($row);
}
return $objectList;
} elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) {
$propertyName = lcfirst(substr($methodName, 9));
$sql = "select * from " . $this->tableName . " where id = :id";
$row = $this->db->fetchAssoc($sql, array('id' => $arguments[0]));
if ($row) {
return $this->buildDomainObject($row);
} else {
throw new \Exception("No " . $this->objectName . " matching " . $propertyName . " " . $arguments[0]);
}
} elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) {
$propertyName = lcfirst(substr($methodName, 7));
$sql = "select COUNT(id) from " . $this->tableName . " where " . $propertyName . " = :propertyValue order by id desc";
$result = current($this->db->fetchAssoc($sql, array('propertyValue' => $arguments[0])));
return $result;
}
throw new \Exception('The method "' . $methodName . '" is not supported by the repository.', 1233180480);
}
示例3: findOne
public function findOne($id)
{
$sql = "SELECT * FROM articles WHERE id = ?";
$result = $this->db->fetchAssoc($sql, array((int) $id));
$article = $this->buildArticle($result[0]);
return $article;
}
示例4: findByNameAndPassword
public function findByNameAndPassword($admin)
{
$name = $admin->getName();
$password = $admin->getPassword();
$adminData = $this->db->fetchAssoc('SELECT * FROM admin WHERE name = ? and password = ?', array($name, $password));
return $adminData ? $this->buildAdmin($adminData) : FALSE;
}
示例5: count
public function count()
{
$qb = $this->dbal->createQueryBuilder();
$qb->select('count(*) c')->from('(' . $this->qb->getSQL() . ')', 'xxx');
$row = $this->dbal->fetchAssoc($qb->getSQL());
return $this->count = intval($row['c']);
}
示例6: findByUriValid
public function findByUriValid($uri)
{
$sql = "SELECT * FROM {$this->entityTable} WHERE uri = ? AND compromised=0";
$row = $this->db->fetchAssoc($sql, array((string) $uri));
if ($row) {
return $this->createEntity($row);
}
}
示例7: find
public function find($id)
{
$record = $this->conn->fetchAssoc("SELECT id, message, author, parent FROM messages WHERE id = :id", [':id' => $id]);
if (!$record) {
throw new ObjectNotFoundException("Message not found for ID: {$id}");
}
return $record;
}
示例8: getCredentialChangeRequest
public function getCredentialChangeRequest($id, User $currentUser)
{
$data = $this->conn->fetchAssoc('SELECT * FROM `' . CoreTables::CREDENTIAL_CHANGE_TBL . '` WHERE `id` = :id', [':id' => $id]);
if (empty($data) || $data['userId'] != $currentUser->getId()) {
throw new ModelException('The specified credential change request does not exist.');
}
return CredentialChangeRequest::fromArray($currentUser, $data);
}
示例9: getFlowchartConfig
/**
* @param string $workflowId
* @return array|null
*/
public function getFlowchartConfig($workflowId)
{
$flowchartConfig = $this->connection->fetchAssoc("SELECT * FROM {$this->flowchartConfigTable} WHERE workflow_id = :id", ['id' => $workflowId]);
if (!$flowchartConfig) {
return null;
}
return ['workflow_id' => $flowchartConfig['workflow_id'], 'config' => json_decode($flowchartConfig['config']), 'last_updated_at' => $flowchartConfig['last_updated_at']];
}
示例10: findByUsername
public function findByUsername($username)
{
$record = $this->conn->fetchAssoc("SELECT id, username, age FROM users WHERE username = :username", [':username' => $username]);
if (!$record) {
throw new ObjectNotFoundException("User not found for name: {$username}");
}
return $record;
}
示例11: getVersion
/**
* @return string
*/
public function getVersion()
{
$result = $this->connection->fetchAssoc('SELECT value AS version FROM pref WHERE prop="version"');
if ($result !== false) {
return $result['version'];
}
return VersionRepository::DEFAULT_VERSION;
}
示例12: find
/**
* @param string $id
* @return array|null
*/
public function find($id)
{
$handlerData = $this->connection->fetchAssoc('SELECT * FROM ' . Tables::MESSAGE_HANDLER . ' WHERE id = :id', ['id' => $id]);
if (empty($handlerData)) {
return null;
}
$this->fromDatabase($handlerData);
return $handlerData;
}
示例13: fetchVocabularyByName
public function fetchVocabularyByName($name)
{
$vocabulary = $this->dbal->fetchAssoc('SELECT * FROM taxonomyVocabulary WHERE name = :name', ['name' => $name]);
if ($vocabulary) {
$vocabulary = $this->vocabularyHydrator->hydrate($vocabulary, new Vocabulary());
return $vocabulary;
}
throw new VocabularyNotFoundException('Could not find vocabulary ' . $name);
}
示例14: getBySku
/**
* @param string $sku
* @return Product
* @throws QueryException
*/
public function getBySku(string $sku) : Product
{
$qb = $this->connection->createQueryBuilder();
$qb->select('*')->from('dumplie_inventory_product')->where('sku = :sku')->setParameter('sku', $sku);
$productData = $this->connection->fetchAssoc($qb->getSQL(), $qb->getParameters());
if (empty($productData)) {
throw QueryException::productNotFound($sku);
}
return new Product($productData['sku'], $productData['price_amount'] / $productData['price_precision'], $productData['price_currency'], (bool) $productData['is_in_stock'], $this->mao->getBy([Metadata::FIELD_SKU => $productData['sku']]));
}
示例15: getBySku
/**
* @param SKU $sku
* @return Product
* @throws ProductNotFoundException
*/
public function getBySku(SKU $sku) : Product
{
$queryBuilder = $this->connection->createQueryBuilder();
$queryBuilder->select('sku', 'is_in_stock', 'price_amount', 'price_currency', 'price_precision')->from('dumplie_inventory_product')->where('sku = :sku')->setParameter('sku', (string) $sku);
$result = $this->connection->fetchAssoc($queryBuilder->getSQL(), $queryBuilder->getParameters());
if (!$result) {
throw ProductNotFoundException::bySku($sku);
}
return new Product(new SKU($result['sku']), new Price((int) $result['price_amount'], $result['price_currency'], (int) $result['price_precision']), (bool) $result['is_in_stock']);
}