Common Database Functions Available for Development of Seo Panel Plugin

Common Database Functions

Inside a plugin functions database object can be accessed by $this->db

Eg:
$sql = "Select query”;
projectList = $this->db->select($sql);

The above code will assign the projects list  as an array to variable $projectList

The important functions can be used for database operation are


1) select($query, $fetchFirst = false)

This function is used for database select statement and will return the database table rows as an array.

$query
The sql select query to be executed to get the results.

$fetchFirst
true - Will return only first row of the results
false - Will return all rows and default value is “false”

Return
The array contains the result list. Returns empty  array if query fails or when empty rows retrieved. The return array can be accessed like below example

Eg:
$sql = "select query”;        
$projectList = $this->db->select($sql);
foreach ($projectList as $i => $prInfo) {

echo $prInfo['id'];

}

$sql = "select query”;        
$prInfo = $this->db->select($sql, true);
echo $prInfo['id'];


2) query($query, $noRows=false)

This function is used to execute the sql query like update,delete etc

$query
The sql query to be executed.

$noRows
true - It will set number of database entries affected by execution of query in the variable $this->db->noRows
false - will not set number of database entries affected, default value is “false”

Return
Return the result of the execution like the return variable of php mysql query function