Why is DBAL returning a SQL Syntax Error?
I'm using Doctrine 2 along with CodeIgniter.
I'm having a query in some of my functions that trigger a SQL Error. And I
can't find the reason why
The function is the following:
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;
}
When Key ENtity is :
<?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 ... */
}
And the error message is :
Doctrine\DBAL\DBALException: An exception occurred while executing '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]: Syntax error or access violation: 1064 You have an error
in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'keys t0 WHERE t0.key =
'0fedfa4d50653317df76a4dba79f9f07cd7a8273' LIMIT 1' at line 1 in
E:\Programmes\wamp\www\myapp\application\libraries\Doctrine\DBAL\DBALException.php
on line 47
I do see : Key : c242c67787bd0b9a9b11a54fc942fde50f099235 in the output
though
Many thanks for your help
No comments:
Post a Comment