<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdo-sqlite.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'pdo-sqlite.setauthorizer.php',
    1 => 'Pdo\\Sqlite::setAuthorizer',
    2 => 'Configures a callback to be used as an authorizer to limit what a statement can do',
  ),
  'up' => 
  array (
    0 => 'class.pdo-sqlite.php',
    1 => 'Pdo\\Sqlite',
  ),
  'prev' => 
  array (
    0 => 'pdo-sqlite.openblob.php',
    1 => 'Pdo\\Sqlite::openBlob',
  ),
  'next' => 
  array (
    0 => 'refs.database.vendors.php',
    1 => 'Постачальники окремих розширень баз даних',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo_sqlite/pdo/sqlite/setauthorizer.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdo-sqlite.setauthorizer" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Pdo\Sqlite::setAuthorizer</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.5.0)</p><p class="refpurpose"><span class="refname">Pdo\Sqlite::setAuthorizer</span> &mdash; <span class="dc-title">Configures a callback to be used as an authorizer to limit what a statement can do</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-pdo-sqlite.setauthorizer-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">function</span> <span class="methodname"><strong>Pdo\Sqlite::setAuthorizer</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span></span> <code class="parameter">$callback</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="simpara">
   Sets a callback that will be called by SQLite every time an action is performed
   (reading, deleting, updating, etc.). This is used when preparing an SQL statement
   from an untrusted source to ensure that the statement does not access data it is
   not allowed to see or execute malicious statements that damage the database.
  </p>
  <p class="simpara">
   The authorizer is used only during the statement preparation phase.
   It may be called several times for a single statement: a
   <code class="literal">SELECT</code> or <code class="literal">UPDATE</code> query calls it for every
   column that would be read or updated. It runs again whenever SQLite
   re-prepares a statement, which may happen while the statement is being
   executed, for instance after the schema has changed.
  </p>
  <p class="simpara">
   The authorizer is called with up to five arguments. The arguments received are
   described at <span class="methodname"><a href="sqlite3.setauthorizer.php" class="methodname">SQLite3::setAuthorizer()</a></span>.
  </p>
  <p class="simpara">
   Only a single authorizer can be in place on a database connection at a time.
   Each call to this method overrides the previous one. The authorizer is disabled
   by default, and can be disabled again by setting a <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> callback.
  </p>
  <p class="simpara">
   The callback must not modify the database connection that invoked it.
  </p>
  <p class="simpara">
   More details can be found in the
   <a href="http://sqlite.org/c3ref/set_authorizer.html" class="link external">&raquo;&nbsp;SQLite documentation</a>.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="simpara">
    This method is the equivalent of <span class="methodname"><a href="sqlite3.setauthorizer.php" class="methodname">SQLite3::setAuthorizer()</a></span>,
    except that it returns <span class="type"><span class="type"><a href="language.types.void.php" class="type void">void</a></span></span> instead of <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdo-sqlite.setauthorizer-parameters">
  <h3 class="title">Параметри</h3>
  <dl>
   
    <dt><code class="parameter">callback</code></dt>
    <dd>
     <p class="simpara">
      The <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> to be invoked, or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> to disable the current
      authorizer callback.
     </p>
     <p class="simpara">
      It must return one of <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.ok">Pdo\Sqlite::OK</a></code></strong>,
      <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.deny">Pdo\Sqlite::DENY</a></code></strong>, or
      <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.ignore">Pdo\Sqlite::IGNORE</a></code></strong>.
      When <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.deny">Pdo\Sqlite::DENY</a></code></strong> is returned, the statement that
      triggered the authorizer fails with an error stating that access is denied.
      When <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.ignore">Pdo\Sqlite::IGNORE</a></code></strong> is returned for a read action,
      the statement is prepared so that a <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> value is substituted for the
      column that would have been read.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo-sqlite.setauthorizer-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="simpara">
   Не повертає значень.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdo-sqlite.setauthorizer-errors">
  <h3 class="title">Помилки/виключення</h3>
  <p class="simpara">
   This method itself does not throw, but if the authorizer callback does not return
   an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>, or returns an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> which is not one of
   <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.ok">Pdo\Sqlite::OK</a></code></strong>, <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.deny">Pdo\Sqlite::DENY</a></code></strong>, or
   <strong><code><a href="class.pdo-sqlite.php#pdo-sqlite.constants.ignore">Pdo\Sqlite::IGNORE</a></code></strong>, the statement preparation throws a
   <span class="exceptionname"><a href="class.typeerror.php" class="exceptionname">TypeError</a></span> or a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>
   respectively.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo-sqlite.setauthorizer-examples">
  <h3 class="title">Приклади</h3>
  <div class="example" id="example-1">
   <p><strong>Приклад #1 <span class="methodname"><strong>Pdo\Sqlite::setAuthorizer()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    Only read actions are allowed on the connection. The action codes are exposed
    as <span class="classname"><a href="class.sqlite3.php" class="classname">SQLite3</a></span> class constants, which requires the
    <a href="book.sqlite3.php" class="link">SQLite3</a> extension to be available; their
    integer values may be used directly otherwise.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
$db </span><span style="color: #007700">= new </span><span style="color: #0000BB">Pdo\Sqlite</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlite::memory:'</span><span style="color: #007700">);
</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'CREATE TABLE users (id, name)'</span><span style="color: #007700">);

</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setAuthorizer</span><span style="color: #007700">(function (</span><span style="color: #0000BB">int $action</span><span style="color: #007700">, ...</span><span style="color: #0000BB">$args</span><span style="color: #007700">) {
    return match (</span><span style="color: #0000BB">$action</span><span style="color: #007700">) {
        </span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">::</span><span style="color: #0000BB">SELECT</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">::</span><span style="color: #0000BB">READ </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">Pdo\Sqlite</span><span style="color: #007700">::</span><span style="color: #0000BB">OK</span><span style="color: #007700">,
        default =&gt; </span><span style="color: #0000BB">Pdo\Sqlite</span><span style="color: #007700">::</span><span style="color: #0000BB">DENY</span><span style="color: #007700">,
    };
});

</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT name FROM users'</span><span style="color: #007700">) instanceof </span><span style="color: #0000BB">PDOStatement</span><span style="color: #007700">);

try {
    </span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'DROP TABLE users'</span><span style="color: #007700">);
} catch (</span><span style="color: #0000BB">PDOException $e</span><span style="color: #007700">) {
    echo </span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">(), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;
}
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

   <div class="example-contents"><p>Поданий вище приклад виведе щось
схоже на:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">bool(true)
SQLSTATE[HY000]: General error: 23 not authorized</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdo-sqlite.setauthorizer-seealso">
  <h3 class="title">Прогляньте також</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="sqlite3.setauthorizer.php" class="methodname" rel="rdfs-seeAlso">SQLite3::setAuthorizer()</a> - Configures a callback to be used as an authorizer to limit what a statement can do</span></li>
  </ul>
 </div>


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