Alaa Jabre
Alaa Jabre

Reputation: 1883

odbc_exec vs odbc_excute

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?

Upvotes: 4

Views: 3796

Answers (1)

user1549550
user1549550

Reputation:

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']));
}

Upvotes: 9

Related Questions