Archive for January, 2012

Verify if a table is locked by MySql

Many times you need to understand if a table still locked by mysql.
In this case you can use the following function to understand if it is or not.

* This function will check on the db name pass by the first param
* if one, or more tables, are locked by others processes
* Return true if just one of tables is locked
* @param string $db_name
* @param array $array_tables_names
* @return boolean
function tablesLocked($db_name, $array_tables_names)

//Take the instance of codeigniter
$ci = get_instance();

//Load the default configuration 
//(if your configuration name is different just change it)

//Check for locked tables
$sql = "SHOW OPEN TABLES FROM `".$db_name."`
WHERE In_use > 0
`Table` IN (";

$tables = count($array_tables_names);
for($i = 0; $i < $tables; $i++):
$sql .= "'".$array_tables_names[$i]."'";
if($i < ($tables-1)) $sql .= ",";

$sql .= ")";
$rs = $ci->db->query($sql);
return $rs->num_rows() > 0;

Categories: CodeIgniter, Functions, PHP

watermark image with php and ImageMagick

Here a simple function that use ImageMagick command to apply a watermark image as background of another one.

* Direct command from imagemagick
* composite -dissolve 15 -tile watermark.png source.jpg destination.jpg
* @param string $watermarkfile
* @param string $sourcefile
* @param string $destfile
* @param int $dissolve
* @return boolean
function watermarkImage($watermarkfile, $sourcefile, $destfile, $dissolve = 5)
$cmd = "/usr/bin/composite -dissolve $dissolve -tile $watermarkfile $sourcefile $destfile";

exec($cmd, $output, $return);
return $return === 0;

Categories: Bash scripting, Functions, PHP

Javascript right click disabled

Here a simple function to disable the right click and also the key of contextmenu from javascript:

<script type='text/javascript'>
 var isNS = (navigator.appName == "Netscape") ? 1 : 0;
  if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
  function mischandler(){
   return false;
  function mousehandler(e){
 	var myevent = (isNS) ? e : event;
 	var eventbutton = (isNS) ? myevent.which : myevent.button;
    if((eventbutton==2)||(eventbutton==3)) return false;
 document.oncontextmenu = mischandler;
 document.onmousedown = mousehandler;
 document.onmouseup = mousehandler;
Categories: JavaScript
%d bloggers like this: