PHP Classes
elePHPant
Icontem

File: bt-include/db-specific.functions.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michael Dale  >  Bluetrait  >  bt-include/db-specific.functions.php  >  Download  
File: bt-include/db-specific.functions.php
Role: Auxiliary script
Content type: text/plain
Description: Database Specific Functions File
Class: Bluetrait
A multi-user blog system
Author: By
Last change:
Date: 6 years ago
Size: 2,537 bytes
 

Contents

Class file image Download
<?php
/*
    Bluetrait 2.0 Database Specific Functions
    Michael Dale Copyright 2007
*/
function bt_is_installed() {
    global
$bt_db, $bt_tb, $bt_db_type;
   
    switch (
$bt_db_type) {
        case
'postgresql':
           
$stmt = $bt_db->prepare("SELECT table_name FROM information_schema.tables WHERE table_schema = '$bt_tb->site'");
        break;
       
        case
'sqlite':
           
$stmt = $bt_db->prepare("SELECT * FROM SQLITE_MASTER WHERE tbl_name='$bt_tb->site'");
        break;
       
       
//mysql
       
default:
           
$stmt = $bt_db->prepare("SHOW TABLES LIKE '$bt_tb->site'");
    }
    try {
       
$stmt->execute();
    }
    catch (
Exception $e) {
       
bt_die($e->getMessage());
    }
   
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
    if (!isset(
$array[0])) return false;
   
    return
true;
}

function
bt_optimise_tables() {
    global
$bt_db, $bt_tb, $bt_db_type;

    switch (
$bt_db_type) {
        case
'mysql':
           
$optimise_tables = '';
            foreach (
$bt_tb->tables as $value => $index) {
               
$optimise_tables .= $index . ',';
            }
           
$optimise_tables = substr($optimise_tables, 0, strlen($optimise_tables) - 1);
           
$query = 'OPTIMIZE TABLE ' . $optimise_tables;
           
trigger_error('Optimising Tables', E_USER_NOTICE);
            foreach (
$bt_db->query($query, PDO::FETCH_ASSOC) as $row) {
                if (
$row['Msg_type'] == 'error') {
                   
$type = E_USER_WARNING;
                }
                else {
                   
$type = E_USER_NOTICE;
                }
               
trigger_error('Table "' . bt_htmlentities($row['Table']) . '"<br />Message "' . bt_htmlentities($row['Msg_text']) . '"', $type);
            }
           
trigger_error('Optimised Tables', E_USER_NOTICE);
        break;
       
        case
'sqlite':
        break;
       
        case
'postgresql':
        break;
    }
}

function
bt_repair_tables() {
    global
$bt_db, $bt_tb, $bt_db_type;

    switch (
$bt_db_type) {
        case
'mysql':
           
$repair_tables = '';
            foreach (
$bt_tb->tables as $value => $index) {
               
$repair_tables .= $index . ',';
            }
           
$repair_tables = substr($repair_tables, 0, strlen($repair_tables) - 1);
           
$query = 'REPAIR TABLE ' . $repair_tables;
           
trigger_error('Repairing Tables', E_USER_NOTICE);
            foreach (
$bt_db->query($query, PDO::FETCH_ASSOC) as $row) {
                if (
$row['Msg_type'] == 'error') {
                   
$type = E_USER_WARNING;
                }
                else {
                   
$type = E_USER_NOTICE;
                }
               
trigger_error('Table "' . bt_htmlentities($row['Table']) . '"<br />Message "' . bt_htmlentities($row['Msg_text']) . '"', $type);
            }
           
trigger_error('Repaired Tables', E_USER_NOTICE);
       
        break;
       
        case
'sqlite':
        break;
       
        case
'postgresql':
        break;
   
    }

}

?>