Menggunakan User Defined Variable Sebagai Counter Di MySQL
Sedikit tips mengenai penggunaan User-Defined Variable di MySQL. Buat yang belum tau apa itu user-defined variable. Ini adalah variable yang hanya hidup di satu koneksi MySQL. Dalam artian, user yang login dengan koneksi lain, tidak akan bisa melihat variable ini. Begitu juga bila kita sudah logout dari koneksi tersebut, tidak akan bisa melihat variable yang sama, saat login kembali.
MySQL Trick: Group_Concat()
Apakah anda sering menggunakan potongan kode seperti ini:
<?php
$sql = "SELECT tag FROM contoh_table";
$rs = mysql_query( $sql );
$array_tags = array();
while( false !== ( $r = mysql_fetch_assoc($rs)))
{
$array_tags[] = $r['id'];
}
echo "Tags: " . implode(', ', $array_tags);
?>
Saya ada satu cara yang lebih mudah.
How To Create New MySQL User In Ubuntu
Few days ago I created a tutorial on how to create new database and table in mysql, in ubuntu and using GUI tool. Now, in this tutorial, I'll show you how to create new MySQL user using the same GUI tool.
How To Create MySQL Database on Ubuntu
So, you have choose to live with ubuntu. That's great! But you came from windows world where there's so many mysql frontend application in which you are able to create table easily. That's OK, we also have many mysql front-end applications in linux.
Mengubah Default DataDir MySQL di Ubuntu Hardy
Dari awal saya memakai linux, saya selalu memindah datadir mysql di laptop saya ke tempat lain di /home. Tujuannya apa? agar setiap kali upgrade atau install ulang linux, saya tidak perlu repot-repot backup data mysql. Kan repot tuh, apa lagi kalau sampai lupa backup, bisa kacau. Begitu juga dengan setting httpd.conf apache. Tapi ini untuk artikel lain saja. Yang membuat saya menulis artikel ini karena saya tidak tahu kalau ubuntu hardy secara default sudah menyertakan AppArmor. Cara mengubah datadir itu sederhana, coba ikuti langkah2 berikut:
Mimic Oracle’s LOV Feature for Web Application Part 2: Add Database Support
On my previous tutorial, you have seen how to create a Lookup Grid. That's just basic, without database support.
In this tutorial, I'll enhance the script with database and search support. What you'll need first is obviously a database server. If you don't have the tutorial file, please download it from my previous tutorial. Next think to do is, create a file which contain database information. Let's call it db_conn.php.
<?php
$conn = mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('database_name');
?>
With database information obtained, now we'll move to lov.php file. Open it and include db_conn.php.
include('db_conn.php');
Next, delete all <row></row> xml data. Add this code right after header("Content-Type: text/xml");.
$x = isset($_GET['query']) ? $_GET['query'] : '';
$addSQL = "";
if(!empty($x)){
$addSQL = "WHERE name LIKE '%".mysql_escape_string($x)."%'";
}
$sql = "SELECT * FROM friends $addSQL";
$rs = mysql_query($sql, $conn);
On place where <row></row> was, add this code:
<?php
$select = 'selected="1"';
while(false !== ($r = mysql_fetch_array($rs))){
echo '
<row id="'.$r['id'].'" '.$select.'>
<cell>'.$r['id'].'</cell>
<cell>'.$r['name'].'</cell>
<cell>'.$r['city'].'</cell>
<cell>'.$r['phone'].'</cell>
<cell>'.$r['email'].'</cell>
</row>
';
$select = "";
}
?>
Now the XML generator part is ready, now we'll head to HTML part.
Please add this code right before <div id="gridbox" height="100%"></div>
<div id="searchbox">
Search <input type="text" id="searchText" value="">
<input type="button" onclick="doLimit(document.getElementById('searchText').value)" value="Search">
</div>
And this javascript function inside HTML HEAD tag.
<script language="javascript" type="text/javascript">
var mygrid = null;
function doLimit(txt){
mygrid.clearAll();
mygrid.loadXML("lov.php?reqType=getXML&query="+txt);
}
</script>
That's it, save your lov.php file and run it to test. You can also try in online here
and download the example file here. Any question you might have, you can write in here in comment form below.
I'll try to answer when I have time.








