PHP: Hypertext Preprocessor (original) (raw)
odbc_do
(PHP 4, PHP 5, PHP 7, PHP 8)
odbc_do — Alias of odbc_exec()
Found A Problem?
17 years ago
`Hey guys,
I used the following code to run normal double quotes inside my SQL queries. Hopefully this will save someone else a headache or two-
`
18 years ago
`To clear up: the SQL standard requires strings to be inside single quotes: 'string'. It simply does not accept double quotes for this purpose.
Furthermore, in PHP, you can have a single quote inside double quotes: "select a from b where c = 'string'" without the need to escape.
`
yashkhopade at hotmail dot com ¶
21 years ago
`i have use this function so many times. it works well for my requirements. ok well done...
sqlstr="SELECTbillnoFROMSCROL";<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>q</mi><mi>u</mi><mi>e</mi><mi>r</mi><mi>y</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo><mi>o</mi><mi>d</mi><mi>b</mi><msub><mi>c</mi><mi>d</mi></msub><mi>o</mi><mostretchy="false">(</mo></mrow><annotationencoding="application/x−tex">queryresult=odbcdo(</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.8889em;vertical−align:−0.1944em;"></span><spanclass="mordmathnormal"style="margin−right:0.03588em;">q</span><spanclass="mordmathnormal">u</span><spanclass="mordmathnormal">eryres</span><spanclass="mordmathnormal">u</span><spanclass="mordmathnormal">lt</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">=</span><spanclass="mspace"style="margin−right:0.2778em;"></span></span><spanclass="base"><spanclass="strut"style="height:1em;vertical−align:−0.25em;"></span><spanclass="mordmathnormal">o</span><spanclass="mordmathnormal">d</span><spanclass="mordmathnormal">b</span><spanclass="mord"><spanclass="mordmathnormal">c</span><spanclass="msupsub"><spanclass="vlist−tvlist−t2"><spanclass="vlist−r"><spanclass="vlist"style="height:0.3361em;"><spanstyle="top:−2.55em;margin−left:0em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmathnormalmtight">d</span></span></span></span><spanclass="vlist−s"></span></span><spanclass="vlist−r"><spanclass="vlist"style="height:0.15em;"><span></span></span></span></span></span></span><spanclass="mordmathnormal">o</span><spanclass="mopen">(</span></span></span></span>conn,sqlstr="SELECT bill_no FROM SCROL"; <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>q</mi><mi>u</mi><mi>e</mi><mi>r</mi><mi>y</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo><mi>o</mi><mi>d</mi><mi>b</mi><msub><mi>c</mi><mi>d</mi></msub><mi>o</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">queryresult=odbc_do(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">q</span><span class="mord mathnormal">u</span><span class="mord mathnormal">eryres</span><span class="mord mathnormal">u</span><span class="mord mathnormal">lt</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">o</span><span class="mord mathnormal">d</span><span class="mord mathnormal">b</span><span class="mord"><span class="mord mathnormal">c</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">d</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">o</span><span class="mopen">(</span></span></span></span>conn,sqlstr="SELECTbillnoFROMSCROL";<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>q</mi><mi>u</mi><mi>e</mi><mi>r</mi><mi>y</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo><mi>o</mi><mi>d</mi><mi>b</mi><msub><mi>c</mi><mi>d</mi></msub><mi>o</mi><mostretchy="false">(</mo></mrow><annotationencoding="application/x−tex">queryresult=odbcdo(</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.8889em;vertical−align:−0.1944em;"></span><spanclass="mordmathnormal"style="margin−right:0.03588em;">q</span><spanclass="mordmathnormal">u</span><spanclass="mordmathnormal">eryres</span><spanclass="mordmathnormal">u</span><spanclass="mordmathnormal">lt</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">=</span><spanclass="mspace"style="margin−right:0.2778em;"></span></span><spanclass="base"><spanclass="strut"style="height:1em;vertical−align:−0.25em;"></span><spanclass="mordmathnormal">o</span><spanclass="mordmathnormal">d</span><spanclass="mordmathnormal">b</span><spanclass="mord"><spanclass="mordmathnormal">c</span><spanclass="msupsub"><spanclass="vlist−tvlist−t2"><spanclass="vlist−r"><spanclass="vlist"style="height:0.3361em;"><spanstyle="top:−2.55em;margin−left:0em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmathnormalmtight">d</span></span></span></span><spanclass="vlist−s"></span></span><spanclass="vlist−r"><spanclass="vlist"style="height:0.15em;"><span></span></span></span></span></span></span><spanclass="mordmathnormal">o</span><spanclass="mopen">(</span></span></span></span>conn,sqlstr); odbc_fetch_row($queryresult,$bills);// if we want to access the records // then we have to write the following codeecho $bills[0];?>the out put for this will:
1
which is actullay first record of resultset.
`