Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is oci_bind_by_name for?

Tags:

php

oracle

what is oci_bind_by_name for? I read the php manual and cannot understand anything. Please someone explain it to me

look at this example :

$name = "O'Reilly";
$stid = oci_parse($mycon, 'INSERT INTO CUSTOMERS (NAME) VALUES (:nm)');
oci_bind_by_name($stid, ':nm', $name, -1);
oci_execute($stid);

what is -1 for?

like image 388
user700792 Avatar asked Apr 16 '11 18:04

user700792


People also ask

What does OCI_ bind_ by_ name do?

Any magically applied quotes will be written into your database because oci_bind_by_name() inserts data verbatim and does not remove quotes or escape characters. Note: If you bind a string to a CHAR column in a WHERE clause, remember that Oracle uses blank-padded comparison semantics for CHAR columns.

What is OCI8 PHP?

OCI8 Obsolete Aliases and Functions. oci_internal_debug — Enables or disables internal debug output.


1 Answers

It binds values to named parameters:

$name = "O'Reilly";
$stid = oci_parse($mycon, 'INSERT INTO CUSTOMERS (NAME) VALUES (:nm)');
oci_bind_by_name($stid, ':nm', $name, -1);
oci_execute($stid);

So when you run that query :nm will be O'Reilly. The -1 means, the bound value should be as long as the variable. It's the default value. You don't have to set it. As long as you are only binding existing variables, you don't need to bother.

You want to use this method because

Binding allows the database to reuse the statement context and caches from previous executions of the statement, even if another user or process originally executed it. Binding reduces SQL Injection concerns because the data associated with a bind variable is never treated as part of the SQL statement. It does not need quoting or escaping.

which means it is more secure and has better performance.

like image 104
Gordon Avatar answered Oct 05 '22 17:10

Gordon