Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

odbc_exec vs odbc_excute

Tags:

php

odbc

from php manual:

odbc_exec — Prepare and execute an SQL statement

odbc_execute — Execute a prepared statement

which is prepared by odbc_prepare

so what is the different? why not to use odbc_exec directly?

like image 654
Alaa Jabre Avatar asked Jan 15 '23 23:01

Alaa Jabre


1 Answers

If you want to execute the same statement multiple times with different parameters, then you prepare it once, and execute the prepared statement multiple times. Some RDBMS' will compile the statement when you prepare it, and this saves time when you execute it. This is useful when you have a loop executing the same query inside the loop with different parameters.

For example:

$stm = odbc_prepare($conn, 'INSERT INTO users (id, name, email) VALUES (?, ?, ?)');
foreach($users as $user) {
  $success = odbc_execute($stm, array($user['id'], $user['name'], $user['email']));
}
like image 75
Gary G Avatar answered Jan 18 '23 23:01

Gary G