Skip to content

Conditional bindings based on parameter value #21

@DaveWilcock

Description

@DaveWilcock

This is an enhancement request to implement conditional bindings.

This feature would consider the parameter value; if found to be null, would throw the binding away, if not, would attach the defined arbitrary SQL to the relevant portion of the SQL.

A suggested solution to this may be as follows:

<?php
$arr_records = $obj_db->prepare("SELECT * FROM myTable WHERE col1= ?col1 AND col2 = ?col2 ?_cond_col3 order by xxx")
         ->bindIntIfNotNull('cond_col3', "AND col3 = ?", $col3)
         ->bindInt('col1', $col1)
         ->bindInt('col2', $col2)
         ->fetchAll();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions