我正在使用 Doctrine 2 和 CodeIgniter。
我在一些触发 SQL 错误的函数中有一个查询。我找不到原因
功能如下:
private function _key_exists($key)
{
$this->CI->load->library('doctrine');
$em = $this->CI->doctrine->em;
echo "<br />Key : ".$key;
$key_object = $em->getRepository( 'Entity\Key' )->findOneBy( array( 'key' => $key ) );
if( $key_object )
{
return TRUE;
}
else
{
return FALSE;
}
// return $this->db->where(config_item('rest_key_column'), $key)->count_all_results(config_item('rest_keys_table')) > 0;
}
当关键实体是:
<?php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Keys
*
* @ORM\Table(name="keys")
* @ORM\Entity
*/
class Key
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="key", type="string", length=40, precision=0, scale=0, nullable=false, unique=false)
*/
private $key;
/**
* @var integer
*
* @ORM\Column(name="level", type="integer", precision=0, scale=0, nullable=false, unique=false)
*/
private $level;
/**
* @var boolean
*
* @ORM\Column(name="ignore_limits", type="boolean", precision=0, scale=0, nullable=false, unique=false)
*/
private $ignoreLimits;
/**
* @var boolean
*
* @ORM\Column(name="is_private_key", type="boolean", precision=0, scale=0, nullable=false, unique=false)
*/
private $isPrivateKey;
/**
* @var string
*
* @ORM\Column(name="ip_addresses", type="text", precision=0, scale=0, nullable=true, unique=false)
*/
private $ipAddresses;
/**
* @var integer
*
* @ORM\Column(name="date_created", type="integer", precision=0, scale=0, nullable=false, unique=false)
*/
private $dateCreated;
/* Getters and Setters ... */
}
错误信息是:
Doctrine\DBAL\DBALException: 执行 'SELECT t0.id AS id1, t0.key AS key2, t0.level AS level3, t0.ignore_limits AS ignore_limits4, t0.is_private_key AS is_private_key5, t0.ip_addresses AS ip_addresses6, t0 时发生异常.date_created AS date_created7 FROM keys t0 WHERE t0.key = ? LIMIT 1' with params {"1":"0fedfa4d50653317df76a4dba79f9f07cd7a8273"}: SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 E:\Programmes\wamp\www\myapp\application\libraries\ 的第 1 行的 'keys t0 WHERE t0.key = '0fedfa4d50653317df76a4dba79f9f07cd7a8273' LIMIT 1' 附近使用正确的语法Doctrine\DBAL\DBALException.php 第 47 行
我确实看到:Key : c242c67787bd0b9a9b11a54fc942fde50f099235
在输出中
非常感谢您的帮助