snipt

Ctrl+h for KB shortcuts

PHP

Hook Into MySQL Database

1
2
3
4
5
6
7
8
<?php
$host = "localhost";
$username="username";
$password="password";
$database="db";
mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
?>
https://snipt.net/embed/8cf5c0a391da9383afcf2f48e3c59eaa/
/raw/8cf5c0a391da9383afcf2f48e3c59eaa/
8cf5c0a391da9383afcf2f48e3c59eaa
php
PHP
8
2019-06-25T01:38:12
True
False
False
/api/public/snipt/977/
hook-into-mysql-database
<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="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$host</span> <span class="o">=</span> <span class="s2">&quot;localhost&quot;</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$username</span><span class="o">=</span><span class="s2">&quot;username&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$password</span><span class="o">=</span><span class="s2">&quot;password&quot;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$database</span><span class="o">=</span><span class="s2">&quot;db&quot;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="nb">mysql_connect</span><span class="p">(</span><span class="nv">$host</span><span class="p">,</span><span class="nv">$username</span><span class="p">,</span><span class="nv">$password</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="nb">mysql_select_db</span><span class="p">(</span><span class="nv">$database</span><span class="p">)</span> <span class="k">or</span> <span class="k">die</span><span class="p">(</span> <span class="s2">&quot;Unable to select database&quot;</span><span class="p">);</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
mysql, php

Bash

Replace 'foo' with 'bar' in all PHP files in the folder. Recursive.

find . -name "*.php" -print | xargs sed -i 's/foo/bar/g'
https://snipt.net/embed/998916388c416be36115266cd25ea8aa/
/raw/998916388c416be36115266cd25ea8aa/
998916388c416be36115266cd25ea8aa
bash
Bash
1
2019-06-25T11:36:18
True
False
False
/api/public/snipt/862/
replace-foo-with-bar-in-all-php-files-in-the-folder-recursive
<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>find . -name <span class="s2">&quot;*.php&quot;</span> -print <span class="p">|</span> xargs sed -i <span class="s1">&#39;s/foo/bar/g&#39;</span> </span></pre></div> </td></tr></table>
bash, find, php, replace, sed, unix