Adminer: Because SELECT query doesn’t need an overkill tool

How many of you have websites? From those of you ho do, how many are there who regularly do SELECT query against your MySQL databases? Who uses PHPMyAdmin to do those queries? Are you tired and frustrated by the heavy and bloated tools? For me, I would answer “YES” to all of these question

Continue reading “Adminer: Because SELECT query doesn’t need an overkill tool”

Share

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.

Continue reading “Menggunakan User Defined Variable Sebagai Counter Di MySQL”

Share

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.

Continue reading “MySQL Trick: Group_Concat()”

Share

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.

Continue reading “How To Create MySQL Database on Ubuntu”

Share

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:
Continue reading “Mengubah Default DataDir MySQL di Ubuntu Hardy”

Share

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&#91;'id'&#93;.'" '.$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&nbsp;<input type="text" id="searchText" value="">&nbsp;
	<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.

Share