Hi bro,
Here we are my little contribution!
Not very complicated but usefull.
I needed to check the existence of some columns, when updating my bd. I figured it might be useful to others. Simply copy the function into the myslidb.php file.
public function columnExists($table, $column){
$mod = (!is_array($column) ? "simple":"union");
$count = count($column);
if ($count == 0) {
return false;
}
switch($mod){
case "union":
$i = 0;
foreach($column as $col){
$col = "%".$col."%";
$res = $this->rawQuery("SHOW COLUMNS FROM $table LIKE '$col'");
($res?$i++:"");
}
return ($i === $count?true:false);
case "simple":
default:
$column = "%".$column."%";
$res = $this->rawQueryOne("SHOW COLUMNS FROM $table LIKE '$column'");
return ($res?true:false);
}
}
Hi bro, Here we are my little contribution! Not very complicated but usefull. I needed to check the existence of some columns, when updating my bd. I figured it might be useful to others. Simply copy the function into the myslidb.php file.
public function columnExists($table, $column){ $mod = (!is_array($column) ? "simple":"union"); $count = count($column); if ($count == 0) { return false; } switch($mod){ case "union": $i = 0; foreach($column as $col){ $col = "%".$col."%"; $res = $this->rawQuery("SHOW COLUMNS FROM $table LIKE '$col'"); ($res?$i++:""); } return ($i === $count?true:false); case "simple": default: $column = "%".$column."%"; $res = $this->rawQueryOne("SHOW COLUMNS FROM $table LIKE '$column'"); return ($res?true:false); } }
Usage: $res = $db->columnExists($table, $column) if($res === true) .....Code...... else ........
Note: $column can be a single value or an array.
Have a good day, and really a big thank's for this wrapper!