Doctrine\DBAL\Query\QueryBuilder::createPositionalParameter PHP Method

createPositionalParameter() public method

Attention: If you are using positional parameters with the query builder you have to be very careful to bind all parameters in the order they appear in the SQL statement , otherwise they get bound in the wrong order which can lead to serious bugs in your code. Example: $qb = $conn->createQueryBuilder(); $qb->select('u.*') ->from('users', 'u') ->where('u.username = ' . $qb->createPositionalParameter('Foo', PDO::PARAM_STR)) ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', PDO::PARAM_STR))
public createPositionalParameter ( mixed $value, integer $type = PDO::PARAM_STR ) : string
$value mixed
$type integer
return string
    public function createPositionalParameter($value, $type = \PDO::PARAM_STR)
    {
        $this->boundCounter++;
        $this->setParameter($this->boundCounter, $value, $type);
        return "?";
    }

Usage Example

Esempio n. 1
0
File: Not.php Progetto: vlucas/spot2
 /**
  * @param QueryBuilder $builder
  * @param $column
  * @param $value
  * @throws Exception
  * @return string
  */
 public function __invoke(QueryBuilder $builder, $column, $value)
 {
     if (is_array($value) && !empty($value)) {
         return $column . ' NOT IN (' . $builder->createPositionalParameter($value, Connection::PARAM_STR_ARRAY) . ')';
     }
     if ($value === null || is_array($value) && empty($value)) {
         return $column . ' IS NOT NULL';
     }
     return $column . ' != ' . $builder->createPositionalParameter($value);
 }
All Usage Examples Of Doctrine\DBAL\Query\QueryBuilder::createPositionalParameter