pdo, mysqli oop database classes to use with php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    pdo, mysqli oop database classes to use with php

    so i created 2 database classes to use with mysql/php.
    1 x mysqli oop db class
    1 x pdo oop db class

    the aim/point of this was to build some kind of structure to using both mysqli or pdo
    in a slightly more clean/tidy way.

    examples:

    mysqli oop db class usage examples:
    PHP Code:
    require_once('mysqli.class.php');
    // multi row table
    $categories db::mysqli()->query('SELECT * FROM `categories`');
    if(
    $categories->count() > 0):
        foreach(
    $categories->result() as $category):
            echo 
    $category->title'<br/>';
            echo 
    $category->description'<br/>';
        endforeach;
    endif;

    db::mysqli()->query('UPDATE `config` SET `site_name`="codemafia"');

    // single row table
    $query db::mysqli()->query('SELECT * FROM `config`');
    // then use our result function as an array instead:
    $config $query->result()[0];
    echo 
    $config->site_name'<br/>';
    echo 
    $config->timezone'<br/>';

    db::mysqli()->close(); 
    pdo oop db class usage examples:
    PHP Code:
    require_once('pdo.class.php');
    // multi row table
    db::pdo()->query('SELECT * FROM `categories`');
    // or with bind
    //db::pdo()->query('SELECT * FROM `categories` WHERE `id` = :id');
    //$placeholders = array(':id' => '1');
    //db::pdo()->bind($placeholders);
    db::pdo()->execute();
    if(
    db::pdo()->count() > 0):
        foreach(
    db::pdo()->result() as $category):
            echo 
    $category->title'<br/>';
            echo 
    $category->description'<br/>';
        endforeach;
    endif;

    db::pdo()->query('UPDATE `config` SET `site_name`="codemafia"');
    db::pdo()->execute();

    // single row table
    db::pdo()->query('SELECT * FROM `config`');
    db::pdo()->execute();
    // then use our result function as an array instead:
    $config db::pdo()->result()[0];
    echo 
    $config->site_name'<br/>';
    echo 
    $config->timezone'<br/>';

    db::pdo()->close(); 
    the files/classes themselves will be stored/hosted on GitHub due to me maybe updating from time to time/
    you can get the classes yourself here at:


    if anyone likes or uses these. a like/thanks would be appreciated.

    hope you like them.

    p:s i will be getting to work shortly on a new pdo forum type script.
    (ive dropped my mysqli version due to loony talking my ears off about pdo lol)
    i will be hosting/storing the progress of this on GitHub also if anyone will be interested in that also.
    <?php
    include ('Ghost');
    if ($Post == true) {
    echo '

    sigpic
    alt='coding-talk.com!!' />';
    echo 'Sharing Is Caring!';
    } else {
    echo '

    alt='the username GHOST has been comprimised!' />';
    echo 'OMG SOMEBODY HELP ME!!';
    }
    ?>

    #2
    Sweet.. great job man
    wapZan Mobile site builder - Yours is here



    http://wapzan.com?ref=2wap

    Comment


      #3
      thanks bud. glad you like it
      <?php
      include ('Ghost');
      if ($Post == true) {
      echo '

      sigpic
      alt='coding-talk.com!!' />';
      echo 'Sharing Is Caring!';
      } else {
      echo '

      alt='the username GHOST has been comprimised!' />';
      echo 'OMG SOMEBODY HELP ME!!';
      }
      ?>

      Comment


        #4
        haha pdo ghost did i mess with your brain again nice work thou bud
        Creator of
        Epix.Mobi

        Keep an Eye on us Big things coming soon!!!!
        Need something for your site hit me up here

        http://coding-talk.com/forum/main-fo...r-your-wapsite

        Comment


          #5
          indeed loony lol. but at least you like it. it means i did something right at least lol.
          <?php
          include ('Ghost');
          if ($Post == true) {
          echo '

          sigpic
          alt='coding-talk.com!!' />';
          echo 'Sharing Is Caring!';
          } else {
          echo '

          alt='the username GHOST has been comprimised!' />';
          echo 'OMG SOMEBODY HELP ME!!';
          }
          ?>

          Comment

          Working...
          X