PHP: odbc_execute - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

odbc_fetch_array odbc_exec

Last updated: Fri, 26 Jan 2007

view this page in

# odbc_execute

(PHP 3 >= 3.0.6, PHP 4, PHP 5)

odbc_execute -- Execute a prepared statement

## Description

bool odbc_execute ( resource result_id [, array parameters_array] )

Executes a statement prepared with odbc_prepare().Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки. The array `parameters_array` only needs to be given if you really have parameters in your statement.

Parameters in `parameter_array` will be substituted for placeholders in the prepared statement in order. Elements of this array will be converted to strings by calling this function.

Any parameters in `parameter_array` which start and end with single quotes will be taken as the name of a file to read and send to the database server as the data for the appropriate placeholder.

> Замечание: As of PHP 4.1.1, this file reading functionality has the following restrictions:

> - File reading is not subject to any безопасный режим or open-basedir restrictions. This is fixed in PHP 4.2.0.

> - Remote files are not supported.

> - If you wish to store a string which actually begins and ends with single quotes, you must add a space or other non-single-quote character to the beginning or end of the parameter, which will prevent the parameter from being taken as a file name. If this is not an option, then you must use another mechanism to store the string, such as executing the query directly with odbc_exec()).

add a note User Contributed Notes
odbc_execute
a dot brock at hhv-rheinklang dot de
24-Aug-2006 04:38
`I have a solution for the problem with the strings beeing interpreted as filename because of the single quotes:
Just add a blank to the end of the string:
<?php
function odbc_escape_params ($params) {
if (!is_array($params) or empty($params)) {
return array();
}
foreach ($params as $key=>$val) {
if (strlen($val) > 1 and $val{0} == "'" and $val{strlen($val)-1} == "'") {
$params[$key] .= ' ';
}
}
return $params;
}
?>`
mjs at beebo dot org
27-Mar-2006 01:57
`Don't miss the part where it says that if your string starts and ends with a single quote, the string is interpreted as a filename!
This means that you can't do:
$sth = odbc_prepare($dbh, "INSERT INTO people(name) VALUES(?)");
$res = odbc_execute($sth, array($name));
without checking the value of $name--if $name is, say, '\\'c:\\passwords.txt\\'' the contents of c:\\passwords.txt get inserted into your database as a "name".
Also, despite what the documentation suggests, there (incredibly) doesn't appear to be any way to escape your single quotes (via experimentation, and from reading the source): if your string starts and ends with a single quote you cannot use odbc_execute to insert it into the database.`
russell dot brown at removethis dot insignia dot com
09-Feb-2004 12:55
`In reply to tcmleung at yahoo dot com (09-Nov-2001), I would add a caveat that I've found, which is that the odbc.defaultlrl/odbc_longreadlen() values may only apply to odbc->php conversion and not php->odbc (though this may be database-specific). Hence, if you want to post binary data the 4096 byte limit still stands. So you stand a better chance of being able to post binary data using the quoted filename upload procedure described above, rather than using the prepare... execute method with data held in a php variable.`
svemir_AT_baltok.com
06-Sep-2002 10:45
`In reply to cpoirier's note from 04-Mar-2001 03:30:
Currently, Access 2000 DOES support parametrized queries via ODBC. It still seems to have a problem with Memo and OLE fields, but "normal" types work just fine.`
noreply at hotmail dot com
07-Jan-2002 09:41
`i had trouble executing an INSERT using MS ACCESS 2000 - for some reason the problem resolved when I used odbc_connect as opposed to odbc_pconnect. (thought this might help someone else out)`
tcmleung at yahoo dot com
09-Nov-2001 01:22
`odbc has a maximum buffer size, that means it only stores and retrieves a limited size of data to/from database each time. The maximum buffer size is 4096 and set in php.ini (odbc.defaultlrl). You can set it to higher value for larger data access.`
sjericson at mindspring dot com
25-Aug-2001 10:43
`I don't think odbc_prepare and odbc_execute support output parameters for stored procedures on MSSQL. An example of output parameters for MSSQL is at http://support.microsoft.com/support/kb/articles/q174/2/23.asp
Also, my MSSQL driver seems happy only when I use the following incantation:
...code removed...
$stmt=odbc_prepare($conn_id, "exec my_proc_name ?,?,?");
$parms=array("fred","password",5);
if (!odbc_execute($stmt, &$parms)) die("odbc_execute failed");`
reaganpr at hotmail dot com
23-Jul-2001 04:50
`When running the CGI version of 4.0.6 under windows, I came across this error when trying to call a stored procedure in SQL Server using odbc_execute w/ the parameter array set:
FATAL: emalloc(): Unable to allocate 268675669 bytes
Scary error, huh? In my case it just meant that SQL Server couldn't find the stored procedure. Totally my fault, but a rather nondescript error message.
p.`
cpoirier at shelluser dot net
04-Mar-2001 02:30
`A quick note in hopes that my pain will save someone else: Microsoft Access ODBC drivers do not support parameterized queries.`
edrenth at thematec dot nl
17-Oct-2000 06:17
`When used with parameters and the statement fails, you cannot use different arguments anymore, the same arguments as with the failed statement will be used.`
nospam at geht dot net
10-Sep-1999 09:45
`For examples how to use the parameters array see the example for
function.serialize.php
in the Misc. section.`
tony dot wood at revolutionltd dot com
27-May-1999 04:08
`For a simple database insert to a database that has no password and $from and $to are predefined variables.
/* get connection */
$conn=odbc_connect("mydb","","");
/* run insert */
$stmt = odbc_prepare($conn, "INSERT INTO mytable (jor_from, jor_to) VALUES('$from', '$to');" );
/* check for errors */
if (!odbc_execute($stmt)) {
/* error */
echo "Whoops";
}
/* close connection */
odbc_close($conn);`
wntrmute at tampabay dot rr dot com
15-Aug-1998 09:22
`Solid Issue:
Solid defines CHAR, VARCHAR, LONG VARCHAR, BINARY, VARBINARY, and LONG VARBINARY to be a maximum of 2G in length. However, when creating your tables for use with PHP one should choose LONG VARCHAR or LONG VARBINARY for these kinds of fields if you are planning on storing really large or lengthy data. IE: Data exceeding 64k in length such as GIF/JPG, or really huge text areas.`
add a note
odbc_fetch_array odbc_exec

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST