dqyuipw44576
2018-04-11 09:05
浏览 33
已采纳

Doctrine QueryBuilder未定义方法getQuery()

When I execute the method getMachineSettings I get an error:

Fatal error: Uncaught Error: Call to undefined method Doctrine\DBAL\Query\QueryBuilder::getQuery()

$data is an associative array:

$data['param'] = 'ip';
$data['value'] = '192.168.240.10';

If I replace getQuery()->getResult() with execute(), $result contains the query:

SELECT * FROM machine WHERE ip = ?

public function __construct()
{

    try
    {

        $dbconf = parse_ini_file('.htLogin.ini');
        $config = new \Doctrine\DBAL\Configuration();

        $connectionParams = array
            (
                'dbname'    => $dbconf['infoDb'],
                'user'      => $dbconf['infoLogin'],
                'password'  => $dbconf['infoPw'],
                'host'      => $dbconf['infoHost'],
                'driver'    => 'pdo_mysql',
                'charset'   => 'utf8',
                'driverOptions' => array
                    (
                        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
                    )

            );
        $this->mysql = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);

    }
    catch(PDOException $e)
    {

        echo $e -> getMessage();

    }


public function getMachineSettings($data)
{
    $qb = $this->mysql->createQueryBuilder();
    $qb->SELECT('*')
       ->FROM('`machine`')
       ->WHERE($data['param'] . ' = :value');
    $qb->setParameters(
            array
            (
                ':value' => $data['value']
            )
        );

    $results = $qb->getQuery()->getResult();


    var_dump($result);

    return $result;

 }

Do you have any idea why the method getQuery() is not recognised?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题