Pages

Saturday, February 25, 2012

How to check if GD Library is installed?

Try this:

php Code: 
<?php 
if (extension_loaded('gd') && function_exists('gd_info')) {
     echo "It looks like GD is installed";  
}
?>


You could also spit some info about your GD version by doing this:

php Code: 
<?php
  echo "<pre>"; var_dump(gd_info()); echo "</pre>";
 ?>
 
You will definitely get the ans of your GD Library is installed or not.

Inserting and Updating Records Using JDatabase in Joomla

When you are doing simple single table inserts and updates you can use the JDatabase methods to do so. The advantages of using the JDatabase methods is it saves your time from hand coding sql and will escape and correctly quote your inputs for you.

The following will insert a new record into a table:

<?php 
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Insert new record into #__book table.
$ret = $db->insertObject('#__book', $row);
//Get the new record id
$new_id = (int)$db->insertid();
?>
 
This will update an existing record:
<?php
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
//Record to update
$row->rec_id = 200;
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Update the record. Third parameter is table id field that will be used to update.
$ret = $db->updateObject('#__book', $row,'rec_id');
?>
 
You can also use JTable to insert and update records, but requires more initial setup since you have to create a new JTable class for each table you want to modify. Using JTable is preferred if table has many fields to update from a form submit. JTable will automatically bind the form fields to corresponding table fields using the bind() method.

Here is more info on using JTable.