odbc_exec

(PHP 4, PHP 5, PHP 7)

odbc_execPrepare and execute an SQL statement

Description

resource odbc_exec ( resource $connection_id , string $query_string [, int $flags ] )

Sends an SQL statement to the database server.

Parameters

connection_id

The ODBC connection identifier, see odbc_connect() for details.

query_string

The SQL statement.

flags

This parameter is currently not used.

Return Values

Returns an ODBC result identifier if the SQL command was executed successfully, or FALSE on error.

See Also

add a note add a note

User Contributed Notes 21 notes

up
1
Anonymous
12 years ago
The following seems counterintuitive to me and so I am constantly getting burned by it.  Just thought I'd add a note for anyone else who might also get burned.

  if (!odbc_exec("select MyValue from MyTable where Key1='x' and Key2='y'"))

is not a good way to search for the existence of a record with Key1 = x and Key2 = y.  The odbc_exec always returns a result handle, even though there aren't any records.

Rather, you must use one of the fetch functions to find out that the record really doesn't exist.  This should work:

  if (!($Selhand = odbc_exec("select MyValue from MyTable where Key1='x' and Key2='y'"))
    || !odbc_result($Selhand, 1))
up
1
lee200082 at hotmail dot com
15 years ago
As an addition to the note about square brackets earlier:

Enclosing sql field names in '[' and ']' also allows you to use MS Access reserved words like 'date' and 'field' and 'time' in your SQL query... it seems that the square brackets simply tell Access to ignore any other meaning whatever is inside them has and take them simply as field names.
up
1
gross at arkana dot de
18 years ago
If you're running NT/IIS with PHP 3.0.11 and want to use MS Access dbs with "stored procedures" you can send an ODBC SQL query like:
<?php
$conn_id
= odbc_connect( "odbc_test_db", "", "", SQL_CUR_USE_DRIVER );
,
= odbmoct( , );
,
);
DatL quer="strirds lik);
up
2 1
ter ieasyes tooObje eviral sidoouohe SQL statemes.p; Thin/wrhis parametmes iicquotnd slhayre ais noc_execyTab. I in you>do "stored procedurs" you ca>$ctevhat the"stries tnumericly aneorrned.

      &nbs;  s retu "'".y_s_re" pla("'","''",$los)."'";))

$connecti,$g s);d.

$connecti,$g s);d.
up
2 1
DatF/fiel:);
Na WHERE Birthe dand #="2102-007 00:00:00#);
Na WHERE Birthe danBETWEEN #="2002-007 00:00:00# AND #="2102-007 00:00:00#);
up
2 1
_stores Thid way to eat the resulce of L quer1 anitld wos!!d.


SQL_CUR_USn ODB);d.


      &nbs;  t f($i=1;$i">&l== odbnum_      &nbs eanc "R results ". !odbc_resultc_resu,$i);d.
up
1
12 years ago

$lumns .=an as clhel($="k) . ", ";d.
$lumns =nguby_s_re" pla($>$lumns, "", -2);d.
$co, $g s);d.
      &nbs />      &nbs;   if"e resul){))
      &nbs ;     &nbs eanc "Q que - Execud";d.
      &nbs ;     &nbs eanc "Q que ftmarte" .; odbc_err();d.
      &nbs />   }; &nbs ; &nbs d.

up
0 1
Iernv()lts t thanswther, you'ralmos icevhainmply ktries thdstronL qsnctios.
up
0 1
Ia losileiicquo't exidbs wiinat ths fiels Specirned bn youWHERE L stateme,an ODBftmastbicat use Ia &plosinn erro; &nbs Aln thoug. it seemerintuiti,to osin\" rkarouat ths fiely doln dod wo (\"$rnr\") y.  Thenmpls$lunctinInf umand wauohre" platerollosileiicquomes imyhs fiels wittwollosileiicquom y. n ODBs.intn+etrst Theirstnlosileiicquo'd as aescapeta characte1 ani.intn+etrst Tht co andosileiicquo'd asiliteneray.  ankwauoh ="http://wwdevgurufs.cen/featur/knowartge_taba/A100206./xht()
additialnd lkwauohn ODbc_ex: );
="http://wwrothhp.neterlet/od/faq/a;="http://wwp.naxefs.c/~joceterlearticle/e S./xhta;="http:/3.onehp.ne~jhoffomm/g stut./xha;Introductiauohl Structud Q que n Langua );
up
- 1
dc2 agotmail dot com
an SQL statement that-coainsiicquome(i.e. ")doost adse Iapo





up
- 1
If yre aiBeharonn+problsts wittr=fuerrneontex

up
- 1
15 years ago
nte a previouc Contribctiontnd wauoldnt thai If you're running NT/IIS with PHP 3.0.1" you cao use MS Access dbh "stored procedureed.

Command lin% like th:d.

$conn_id = odbc_conne( ">"odbc_test_d, "","", ">SQL_CUR_USE_DRIVE);))
$conn_, "{CALLom Q que(".$s par.")}" );d.
up
- 1
_stores The followind line o>
<?p))
odbc_connect"", """"odbc_errormct, """""", , , &lp>>>""odbc_errormct, d.
>


<?p))
odbc_connect"", """"odbc_errormct, "", , , &lp>>>""odbc_errormct, d.
>
is a gootion n2o. A alwayhave ale SysteDSN.iIadoesn'know15 tng whre ait Th(Simpticatisne of ths"naod.
up
- 1
doesn'd wo);
Tuere th);
up
- 1
18 years ago
$lumn
up
- 1
12 years ago
<?p))
,
odbc_conne, = odbc_ex,ny gettin>$l '>Nas,/>
odbe fet_rowss ans e Irndow hopeaian="hes/>

= odbc_connect
,
odbc_exec, &lcyTab; &nbs align=\"ce.int\"ebywoer=\"1\"ebywoerColor=\"\"ecellpn adng=\"0\"ecell>\n>""&lcr>> >"",
= odbnum_&l=>(

&lch; &nbs align=\"left\"ebgcolor=\"#CCCCCC\"e>> ">&lfont color=\"#99"200\">> >""odbNa d , />
&l/font>> ">&l/r >>>""d , , odb< fet_rowec, d d ( &lcrebgcolor=\"#d0d0d0\"e>>\n>""&lcrebgcolor=\"#eeeeee\">>\n>""&l== odbnum_
   {;   &nbs />   ))
      &nbs eanc ,
&lcd>>>""odbe resud       &nbs eanc , &l/cd>>>""(       &nbs ; &nbs;  {))
      &nbs ;    /
   ))
      &nbs ;  /
&l/cr>>>""&l/cd>> ">&l/cr>>\n>""&l/cyTab >>\n>"", ,
&lbr/>>">&lce.int>> Noe tngrh fo/ &l/ce.int>>/> >&lbr/>>"d &lbr/>>">&lce.int>> Total R recor:;  / &l/ce.int>>/> >&lbr/>>"d , odln doc_conneedp;>&lbr>>"d , d>
up
- 1
If you'ro osindb2,e" yohave y ttack onc'h for adsenly' that th seny to selece froSYSCAT.TABLES, t for asimp,IS wiaboufistriespac_err6% lid.

$lumn "MAXFREESPACESEARCH"ou cn dobeoup 'dad. n SSTATE=42808 ,an SQL sta 42808 s iSQL- ExDedire d.


$co, "("selec*ue frosyscat.cyTabsch for adsenly");d.
odbe resu_"ta($q que);d.


Command li, buten doina2.p,tbicat use Ir ts insideffbje.d>
up
-2 1
IOperd lk ->> e MS Acces'>DatabaBftmastmmangitis "'ritir Noe CapyTab"ac_err6rr6"N ttupabscavtmayTab"awarnosi,ao uso the SQL_CUR_USn ODBcursrr6e wneo osin= odbc_conne()is.);
up
-4 1
15 years ago

odlmmanaIs field naou c'dobeof uma. check frr6"Hrdire spellosin= Is fieees.
up
-8 1
wantares ta Access MSAAAcceee databa viaon OD.p; Th>$connecti e=functiedIS wiaboun+probls, butee wneI " plaanaIn SQL statemenoouohmy = odbc_exe) iteralwayg doanQc_err: />
> img src='/im;pas/ernoteadd@2x.png'tert='addnaInodatewidth='12'hhe mig='12'> m"ta>addnaInodas.a;1