The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SimpleDB is light and easy way to acces your database

Discussion in 'cPanel Developers' started by astkboy2008, Dec 13, 2009.

  1. astkboy2008

    astkboy2008 Registered

    Joined:
    Dec 13, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Mysql driver class for PHP5. Clearly programmed, very easy to use in your application.
    Simple example - getting result from MySQL database
    This is the most simples example, shows how to get results from database.
    PHP:
    require_once('mysql_driver.php'); //include class file

    $DB = new DB_MYSQL//connect to database

    $DB->query('SELECT host FROM user'); //send query

    $buffer $DB->fetch()) //fetch result to array - basic method (from last query)

    echo $buffer['host']; //where 'host' is a name of desired row in table
    But is better to handle variable on query to make sure that you are fetching from right query!
    PHP:
    $query1 $DB->query('SELECT host FROM user'); //send query
    $query2 $DB->query('SELECT password FROM user'); //send query
    $query3 $DB->query('SELECT * FROM help_topic'); //send query :)
    $query4 $DB->query('SELECT user FROM user'); //send query :)

    while($buffer $DB->fetch($query2)) 

            { 

            echo 
    $buffer['password'].'<br>'

            }
    Now you are sure, that result will come from:
    PHP:
    $query2 $DB->query('SELECT password FROM user'); //send query
    Would you like to know number of affected rows by your query?No problem :)
    PHP:
    echo 'Affected rows: '.$DB->numRows(); //List affected records by last query
    Hmm, maybe you want to count queries and and them to your site footer? Here you go:
    PHP:
    echo 'Queries: '.$DB->queries//Number of queries done by script
    Simple yes? All functions are simple
    You are sitting in your admin panel and doing nothing, lets optimize our database!
    PHP:
    $DB->optimizeDB();  //database optimization
    I know, you want to see all queries done by the script, and time of executions
    First, you will have to enable debug mode:

    In mysql_driver.php

    PHP:
    private $debug 2;
    Now after some queries and other functions you can paste this:

    PHP:
    echo $DB->showSyntaxes();
    download it with exmples
    class_database_0.1.9.zip
    or view the class only
    mysql_driver.php
     

Share This Page