Nico12345
Nico12345

Reputation: 41

Can anyone help me how to bind a variable in a String?

Can someone help me in this problem.

function get_shareSearch($conn, $searchBy) { 
$id = "";
if(isset($_GET['share']))
    {
        $id = $_GET['share'];
        if($id == "%")
        {
            $id = "This is not going to work";
        }
    }
$statement = db_create_statement($conn, "SELECT DISTINCT * FROM shares WHERE company LIKE '%" . $id . "%' OR issue_date LIKE '%" . $id ."%' ORDER BY $searchBy ASC" );
db_bind($statement, ':id', $id);
$resultset = db_fetch_resultset($statement); 
return $resultset; 

}

function db_bind($statement, $name, $value) {
return oci_bind_by_name($statement, $name, $value, 30);

}

Warning: oci_bind_by_name(): ORA-01036: illegal variable

can any one help me how to change variable id in the oracle statement so I could still have concatination plus to that to be able to bind the variable? Thank you.

  db_bind($statement, ':id', $id);

Upvotes: 1

Views: 264

Answers (1)

maraca
maraca

Reputation: 8858

To bind variables in a String they have to be concatenated (oracle notation):

 SELECT DISTINCT * FROM shares WHERE company LIKE '%' || :id || '%' OR issue_date LIKE '%' || :id || '%' ORDER BY $searchBy ASC

Upvotes: 2

Related Questions