- 
                Notifications
    You must be signed in to change notification settings 
- Fork 287
Quick Examples
        Damien edited this page Sep 1, 2019 
        ·
        5 revisions
      
    Note: In all these examples no other code is required other than including:
either for version 4.x
// composer is required for version 4
require 'vendor/autoload.php';or for version 3.x
require 'ez_sql_loader.php';Detailed installation instructions can be found on the Installation and Usage page.
<?php
// Insert into the database.
$db->query("INSERT INTO users (id, name, email) VALUES (NULL,'justin','[email protected]')");<?php
// Update the database.
$db->query("UPDATE users SET name = 'Justin' WHERE id = 2");<?php
// Get one variable from the database and print it out.
$var = $db->get_var("SELECT count(\*) FROM users");
echo $var;<?php
// Get one row from the database and print it out.
$user = $db->get_row("SELECT name,email FROM users WHERE id = 2");
// Access data using object syntax.
echo $user->name;
echo $user->email;<?php 
// Select multiple records from the database and print them out.
$users = $db->get_results("SELECT name, email FROM users");
foreach ( $users as $user ) {
  // Access data using object syntax.
  echo $user->name;
  echo $user->email;
}<?php
// Get 'one column' (based on column index) and print it out.
$names = $db->get_col("SELECT name, email FROM users", 0)
foreach ( $names as $name )  {
 echo $name;
}<?php
// Same as above ‘but quicker’
foreach ( $db->get_col("SELECT name, email FROM users", 0) as $name ) {
  echo $name;
}8. debug()
<?php
// Enable debug
$db->debugOn();
// Run a query
$users = $db->get_results("SELECT name, email FROM users");
// Display last query and all associated results.
$db->debug();9. varDump()
<?php
// Display the structure and contents of any result(s) .. or any variable
$results = $db->get_results("SELECT name, email FROM users");
$db->varDump($results);<?php
// Map out the full schema of any given database and print it out.
$db->select("my_database");
foreach ( $db->get_col("SHOW TABLES",0) as $table-name ) {
  $db->debug();
  $db->get_results("DESC $table-name");
}
$db->debug();