Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

PDO: Insert

1
2
3
4
5
6
7
<?php
/* Prepared Statements for INSERT */

$stmt = $db->prepare("INSERT INTO table(field1,field2,field3,field4,field5) VALUES(:field1,:field2,:field3,:field4,:field5)");
$stmt->execute(array(':field1' => $field1, ':field2' => $field2, ':field3' => $field3, ':field4' => $field4, ':field5' => $field5));
$affected_rows = $stmt->rowCount();
?>
https://snipt.net/embed/14f5696754b9d3ef56930e5293602e48/
https://snipt.net/raw/14f5696754b9d3ef56930e5293602e48/
14f5696754b9d3ef56930e5293602e48
php
PHP
7
2016-12-08T06:16:26
True
False
False
Jan 11, 2013 at 04:22 AM
/api/public/snipt/53143/
pdo-insert
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="cm">/* Prepared Statements for INSERT */</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s2">&quot;INSERT INTO table(field1,field2,field3,field4,field5) VALUES(:field1,:field2,:field3,:field4,:field5)&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">execute</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;:field1&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field1</span><span class="p">,</span> <span class="s1">&#39;:field2&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field2</span><span class="p">,</span> <span class="s1">&#39;:field3&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field3</span><span class="p">,</span> <span class="s1">&#39;:field4&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field4</span><span class="p">,</span> <span class="s1">&#39;:field5&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field5</span><span class="p">));</span> </span><span id="L-6"><a name="L-6"></a><span class="nv">$affected_rows</span> <span class="o">=</span> <span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">rowCount</span><span class="p">();</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"prepared statements", PDO, insert, placeholders

SQL

sql force id insert

1
2
3
4
5
6
7
8
SET IDENTITY_INSERT TABLE ON;
                          
INSERT  INTO TABLE
  (ID, ...)
VALUES
  (ID, ...);

SET IDENTITY_INSERT TABLE OFF;
https://snipt.net/embed/109bbb38b4b527f63242168cfdce9b49/
https://snipt.net/raw/109bbb38b4b527f63242168cfdce9b49/
109bbb38b4b527f63242168cfdce9b49
sql
SQL
8
2016-12-10T20:13:05
True
False
False
/api/public/snipt/8651/
sql-force-id-insert
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">SET</span> <span class="n">IDENTITY_INSERT</span> <span class="k">TABLE</span> <span class="k">ON</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">INSERT</span> <span class="k">INTO</span> <span class="k">TABLE</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">(</span><span class="n">ID</span><span class="p">,</span> <span class="p">...)</span> </span><span id="L-5"><a name="L-5"></a><span class="k">VALUES</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">(</span><span class="n">ID</span><span class="p">,</span> <span class="p">...);</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="k">SET</span> <span class="n">IDENTITY_INSERT</span> <span class="k">TABLE</span> <span class="k">OFF</span><span class="p">;</span> </span></pre></div> </td></tr></table>
force, id, insert, sql
Copyrighted, illegal, or inappropriate content? Email [email protected].