PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<odbc_execodbc_fetch_array>
view the version of this page
Last updated: Thu, 21 Aug 2003

odbc_execute

(PHP 3>= 3.0.6, PHP 4 )

odbc_execute -- Execute a prepared statement

Description

bool odbc_execute ( resource result_id [, array parameters_array])

Executes a statement prepared with odbc_prepare().Returns TRUE on success or FALSE on failure. 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.

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.

Note: As of PHP 4.1.1, this file reading functionality has the following restrictions:

  • File reading is not subject to any safe mode 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 escape them or add a space or other non-single-quote character to the beginning or end of the parameter, which will prevent the parameter's 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 add a note User Contributed Notes
odbc_execute
gcleavesNOSPAM at mag-global dot NO_SPAM dot com
31-Oct-2002 08:09
Despite the previous post's claim that parametrized queries work in MS Access, I have had NO LUCK getting them to work.  I can get them to work with a different odbc data source, MSSQL, but not Access.  Everything in my script is equal, the only difference being the datasource.

I am using an Access 97 database (2000 didn't work either) and ODBC driver version 4.00.6200.00 with Windows 2000.  Perhaps somebody that has made it work could give a clear example of how.
svemir_AT_baltok.com
07-Sep-2002 12: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
08-Jan-2002 01: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 05: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
26-Aug-2001 12: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
24-Jul-2001 06: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 06: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 09: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
11-Sep-1999 11: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
28-May-1999 06: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
16-Aug-1998 11: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.

<odbc_execodbc_fetch_array>
 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: http://php.mirrors.ilisys.com.au/
Last updated: Sat 01 Nov 2003 04:13:36 EST EST