snipt

Ctrl+h for KB shortcuts

MySQL

Mysql importing errors

SET foreign_key_checks = 0;
https://snipt.net/embed/de729115ea11ac53277b45d415e8d9f9/
/raw/de729115ea11ac53277b45d415e8d9f9/
de729115ea11ac53277b45d415e8d9f9
mysql
MySQL
1
2019-07-14T16:39:13
True
False
False
Mar 30, 2014 at 09:22 PM
/api/public/snipt/126066/
mysql-importing-errors
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kt">SET</span> <span class="n">foreign_key_checks</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> </span></pre></div> </td></tr></table>
importing, mysql, sql

PHP

PHP: mysql return last inserted ID

1
2
3
4
5
<?php

$query = "SELECT LAST_INSERT_ID() FROM $table";
$this->query($query, $result);
return current($result[0]);
https://snipt.net/embed/71fd122c99d0d52a9215041a05a36da1/
/raw/71fd122c99d0d52a9215041a05a36da1/
71fd122c99d0d52a9215041a05a36da1
php
PHP
5
2019-06-12T02:36:20
True
False
False
/api/public/snipt/19191/
php-mysql-return-last-inserted-id
<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></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><span id="L-3"><a name="L-3"></a><span class="nv">$query</span> <span class="o">=</span> <span class="s2">&quot;SELECT LAST_INSERT_ID() FROM </span><span class="si">$table</span><span class="s2">&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">query</span><span class="p">(</span><span class="nv">$query</span><span class="p">,</span> <span class="nv">$result</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="k">return</span> <span class="nb">current</span><span class="p">(</span><span class="nv">$result</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span> </span></pre></div> </td></tr></table>
mysql, php

SQL

Use found_rows() in MySQL

1
2
3
4
// use found_rows() as a sql function
mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
    -> WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();
https://snipt.net/embed/7f96bfa1e2c3e7c31588a310d9691404/
/raw/7f96bfa1e2c3e7c31588a310d9691404/
7f96bfa1e2c3e7c31588a310d9691404
sql
SQL
5
2019-07-13T23:03:04
True
False
False
/api/public/snipt/11548/
use-found_rows-in-mysql
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">//</span> <span class="n">use</span> <span class="n">found_rows</span><span class="p">()</span> <span class="k">as</span> <span class="n">a</span> <span class="k">sql</span> <span class="k">function</span> </span><span id="L-2"><a name="L-2"></a><span class="n">mysql</span><span class="o">&gt;</span> <span class="k">SELECT</span> <span class="n">SQL_CALC_FOUND_ROWS</span> <span class="o">*</span> <span class="k">FROM</span> <span class="n">tbl_name</span> </span><span id="L-3"><a name="L-3"></a> <span class="o">-&gt;</span> <span class="k">WHERE</span> <span class="n">id</span> <span class="o">&gt;</span> <span class="mi">100</span> <span class="k">LIMIT</span> <span class="mi">10</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="n">mysql</span><span class="o">&gt;</span> <span class="k">SELECT</span> <span class="n">FOUND_ROWS</span><span class="p">();</span> </span></pre></div> </td></tr></table>
database, db, mysql, select