<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sqlsrv.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'tr',
  ),
  'this' => 
  array (
    0 => 'function.sqlsrv-prepare.php',
    1 => 'sqlsrv_prepare',
    2 => 'Prepares a query for execution',
  ),
  'up' => 
  array (
    0 => 'ref.sqlsrv.php',
    1 => 'SQLSRV İşlevleri',
  ),
  'prev' => 
  array (
    0 => 'function.sqlsrv-num-rows.php',
    1 => 'sqlsrv_num_rows',
  ),
  'next' => 
  array (
    0 => 'function.sqlsrv-query.php',
    1 => 'sqlsrv_query',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/sqlsrv/functions/sqlsrv-prepare.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.sqlsrv-prepare" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sqlsrv_prepare</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">sqlsrv_prepare</span> &mdash; <span class="dc-title">Prepares a query for execution</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.sqlsrv-prepare-description">
  <h3 class="title">Açıklama</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sqlsrv_prepare</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$conn</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$sql</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$params</code><span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$options</code><span class="initializer"> = ?</span></span><br>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="simpara">
   Prepares a query for execution. This function is ideal for preparing a query
   that will be executed multiple times with different parameter values.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sqlsrv-prepare-parameters">
  <h3 class="title">Bağımsız Değişkenler</h3>
  <dl>
   
    <dt><code class="parameter">conn</code></dt>
    <dd>
     <span class="simpara">
      A connection resource returned by <span class="function"><a href="function.sqlsrv-connect.php" class="function">sqlsrv_connect()</a></span>.
     </span>
    </dd>
   
   
    <dt><code class="parameter">sql</code></dt>
    <dd>
     <span class="simpara">
      The string that defines the query to be prepared and executed.
     </span>
    </dd>
   
   
    <dt><code class="parameter">params</code></dt>
    <dd>
     <p class="para">
      An array specifying parameter information when executing a parameterized
      query. Array elements can be any of the following:
      <ul class="simplelist">
       <li>A literal value</li>
       <li>A PHP variable</li>
       <li>An array with this structure:
       array($value [, $direction [, $phpType [, $sqlType]]])</li>
      </ul>
      The following table describes the elements in the array structure above:
      </p>
      <table class="doctable table">
      <caption><strong>Array structure</strong></caption>
      
       <thead>
        <tr>
         <th>Element</th>
         <th>Description</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>$value</td>
         <td>A literal value, a PHP variable, or a PHP by-reference variable.</td>
        </tr>

        <tr>
         <td>$direction (optional)</td>
         <td>One of the following SQLSRV constants used to indicate the
         parameter direction: SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, SQLSRV_PARAM_INOUT.
         The default value is SQLSRV_PARAM_IN.         </td>
        </tr>

        <tr>
         <td>$phpType (optional)</td>
         <td>A SQLSRV_PHPTYPE_* constant that specifies PHP data type of the
         returned value.</td>
        </tr>

        <tr>
         <td>$sqlType (optional)</td>
         <td>A SQLSRV_SQLTYPE_* constant that specifies the SQL Server data
         type of the input value.</td>
        </tr>

       </tbody>
      
     </table>

    </dd>
   
   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <span class="simpara">
      An array specifying query property options. The supported keys are described
      in the following table:
     </span>
     <table class="doctable table">
      <caption><strong>Query Options</strong></caption>
      
       <thead>
        <tr>
         <th>Key</th>
         <th>Values</th>
         <th>Description</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>QueryTimeout</td>
         <td>A positive integer value.</td>
         <td>Sets the query timeout in seconds. By default, the driver will
         wait indefinitely for results.</td>
        </tr>

        <tr>
         <td>SendStreamParamsAtExec</td>
         <td><strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> (the default is <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>)</td>
         <td>Configures the driver to send all stream data at execution (<strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>),
         or to send stream data in chunks (<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>). By default, the value is set to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
         For more information, see <span class="function"><a href="function.sqlsrv-send-stream-data.php" class="function">sqlsrv_send_stream_data()</a></span>.</td>
        </tr>

        <tr>
         <td>Scrollable</td>
         <td>SQLSRV_CURSOR_FORWARD, SQLSRV_CURSOR_STATIC, SQLSRV_CURSOR_DYNAMIC,
         or SQLSRV_CURSOR_KEYSET</td>
         <td>See <a href="http://msdn.microsoft.com/en-us/library/ee376927.aspx" class="link external">&raquo;&nbsp;Specifying a Cursor Type and Selecting Rows</a>
         in the Microsoft SQLSRV documentation.</td>
        </tr>

       </tbody>
      
     </table>

    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-prepare-returnvalues">
  <h3 class="title">Dönen Değerler</h3>
  <p class="simpara">
   Returns a statement resource on success and <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if an error occurred.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sqlsrv-prepare-examples">
  <h3 class="title">Örnekler</h3>
  <div class="example" id="example-1">
   <p><strong>Örnek 1 <span class="function"><strong>sqlsrv_prepare()</strong></span> example</strong></p>
   <div class="example-contents"><p>
   This example demonstrates how to prepare a statement with <span class="function"><strong>sqlsrv_prepare()</strong></span>
   and re-execute it multiple times (with different parameter values) using <span class="function"><a href="function.sqlsrv-execute.php" class="function">sqlsrv_execute()</a></span>.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$serverName </span><span style="color: #007700">= </span><span style="color: #DD0000">"serverName\sqlexpress"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo </span><span style="color: #007700">= array( </span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"dbName"</span><span style="color: #007700">, </span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">( </span><span style="color: #0000BB">$serverName</span><span style="color: #007700">, </span><span style="color: #0000BB">$connectionInfo</span><span style="color: #007700">);<br />if( </span><span style="color: #0000BB">$conn </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    die( </span><span style="color: #0000BB">print_r</span><span style="color: #007700">( </span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"UPDATE Table_1<br />        SET OrderQty = ?<br />        WHERE SalesOrderID = ?"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Initialize parameters and prepare the statement.<br />// Variables $qty and $id are bound to the statement, $stmt.<br /></span><span style="color: #0000BB">$qty </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$id </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_prepare</span><span style="color: #007700">( </span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$sql</span><span style="color: #007700">, array( &amp;</span><span style="color: #0000BB">$qty</span><span style="color: #007700">, &amp;</span><span style="color: #0000BB">$id</span><span style="color: #007700">));<br />if( !</span><span style="color: #0000BB">$stmt </span><span style="color: #007700">) {<br />    die( </span><span style="color: #0000BB">print_r</span><span style="color: #007700">( </span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">// Set up the SalesOrderDetailID and OrderQty information.<br />// This array maps the order ID to order quantity in key=&gt;value pairs.<br /></span><span style="color: #0000BB">$orders </span><span style="color: #007700">= array( </span><span style="color: #0000BB">1</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">20</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Execute the statement for each order.<br /></span><span style="color: #007700">foreach( </span><span style="color: #0000BB">$orders </span><span style="color: #007700">as </span><span style="color: #0000BB">$id </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$qty</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">// Because $id and $qty are bound to $stmt1, their updated<br />    // values are used with each execution of the statement.<br />    </span><span style="color: #007700">if( </span><span style="color: #0000BB">sqlsrv_execute</span><span style="color: #007700">( </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">) === </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br />          die( </span><span style="color: #0000BB">print_r</span><span style="color: #007700">( </span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.sqlsrv-prepare-notes">
  <h3 class="title">Notlar</h3>
  <p class="simpara">
   When you prepare a statement that uses variables as parameters, the variables
   are bound to the statement. This means that if you update the values of the
   variables, the next time you execute the statement it will run with updated
   parameter values. For statements that you plan to execute only once, use
   <span class="function"><a href="function.sqlsrv-query.php" class="function">sqlsrv_query()</a></span>.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sqlsrv-prepare-seealso">
  <h3 class="title">Ayrıca Bakınız</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.sqlsrv-execute.php" class="function" rel="rdfs-seeAlso">sqlsrv_execute()</a> - Executes a statement prepared with sqlsrv_prepare</span></li>
   <li><span class="function"><a href="function.sqlsrv-query.php" class="function" rel="rdfs-seeAlso">sqlsrv_query()</a> - Prepares and executes a query</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>