Documenation

MySQL

/_plugins/buffer.php

This plug-in handles MySQL database connections and queries.

SQL queries

Use $model->db-gt;sql() to execute SQL queries and $model->db->result to access the result. The type of result depends on the type of query:

  • SELECT, SHOW, EXPLAIN
    An array containing the returned rows.
  • INSERT
    The id of the inserted row.
  • UPDATE, DELETE and all others
    The number of affected rows.

Example:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
<?php
$model
->db->sql('
    SELECT
        *
    FROM `' 
$model->db->prefix 'foo`
    WHERE
        `bar` = "' 
$model->db->escape($bar) . '"
    ;'
);

if ( 
$r $model->db->result )
{
    
print_r($r);
}
?>

Class

$model->db

Public functions

  • $model->db->close ( resource $link )
    Closes a database connection.
  • $model->db->escape ( string|array $v )
    Escapes strings for safe database insertion and HTML. Note that $model->POST_db_safe values are already escaped.
  • $model->db->sanitize ( string|array $v )
    Sanitizes user input (make safe for HTML and database insertion).
  • $model->db->query ( string $sql )
    Executes an SQL query.

Public variables

  • $model->db->link
    Database connection resource.
  • $model->db->result
    Returned result from query that was executed last (depending on the type of query this is either an array of returned rows, the id of the last inserted row or the number of affected rows).