PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Raul  >  PHP MySQLi extension class  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Test and Exemple
Class: PHP MySQLi extension class
Execute common queries with MySQLi
Author: By
Last change:
Date: 2 years ago
Size: 1,042 bytes
 

Contents

Class file image Download
<?php
// This is a basic exemplo of the use of the ExMysqli Class
// The class extends the MySqli class
// So you can use the native mysqli methods as well

// I always use these functions on tests scripts, helps me to show the content on the screen
function dump($var){echo '<pre>';var_dump($var);echo '</pre>';}
function
br($repeat = 2){echo str_repeat('<br/>', $repeat);}

include_once
'Database/ExMysqli.php';

$db = new ExMysqli('localhost', 'root', '', 'test');

// Here the data to be inserted
$data = array(
       
'nome' => 'My Name',
       
'email' => 'mymain@domain.com',
       
'telefone' => '45514551',
       
'endereco' => 'Madson Avenue'
);

// Inserting the data
$db->insert('tabela', $data);

// Getting the content
$result = $db->select('*')->from('tabela')->get();

// If there's more then 0 rows returned then fetch and show
if($result->num_rows > 0){
    foreach(
$result->fetch_all(MYSQLI_ASSOC) as $field=>$row) {
       
dump($row);
       
br();
    }
}

// Delete the row with id 1
$db->delete_by_id('tabela', 'id', 1);