Exemplo n.º 1
0
 /** Read the last error from the database and call the parent method to display
  *  this error to the user.
  *  @param $code    Optional you could set a code that should be displayed to the user.
  *                  Per default the database error code will be read and displayed.
  *  @param $message Optional you could set a message that should be displayed to the user.
  *                  Per default the database error message will be read and displayed.
  *  @return Will exit the script and returns a html output with the error informations.
  */
 public function db_error($code = 0, $message = '')
 {
     if ($code === 0) {
         parent::db_error(1, @pg_last_error());
     } else {
         parent::db_error($code, $message);
     }
 }
Exemplo n.º 2
0
 public function __construct($config = array())
 {
     $this->db = DBCommon::run();
     $this->prefix = Config::get('Database', 'prefix');
     if (empty($config)) {
         $config = Config::get('Database');
     }
     $this->db->connect($config);
 }
Exemplo n.º 3
0
 /** Read the last error from the database and call the parent method to display
  *  this error to the user.
  *  @param $code    Optional you could set a code that should be displayed to the user.
  *                  Per default the database error code will be read and displayed.
  *  @param $message Optional you could set a message that should be displayed to the user.
  *                  Per default the database error message will be read and displayed.
  *  @return Will exit the script and returns a html output with the error informations.
  */
 public function db_error($code = 0, $message = '')
 {
     if ($code === 0) {
         if (!$this->connectId) {
             parent::db_error(@mysql_errno(), @mysql_error());
         } else {
             parent::db_error(@mysql_errno($this->connectId), @mysql_error($this->connectId));
         }
     } else {
         parent::db_error($code, $message);
     }
 }
Exemplo n.º 4
0
 function __construct($pdo_obj)
 {
     $table_name = "gender";
     parent::__construct($table_name, $pdo_obj);
 }
Exemplo n.º 5
0
<?php

require 'DBCommon.php';
$db = new DBCommon('localhost', 'root', 'root', 'acashop');
// (1)
// Create a form that accepts a product id
// Display that product
// (2)
// Bonus: Create a dropdown that has all product names
// Let the user select the productName
// Display that product, by Id
?>
    <form name="productForm" action="<?php 
echo $_SERVER['PHP_SELF'];
?>
" method="post">

<!--         Write a query to get this select dropdown. Display product names -->
        <select name="productId">
            <option value=""></option>
            <option value="1">DomoKun</option>
            <option value="3">Painting</option>
        </select>

        <!--    and a submit button -->
        <input type="submit"/>
    </form>

<?php 
// Receive the user input and do stuff
if ($_POST) {
Exemplo n.º 6
0
<?php

// Include the DB file
require 'DBCommon.php';
$db = new DBCommon('localhost', 'root', 'root', 'acashop');
$query = 'select * from aca_product';
$db->setQuery($query);
$products = $db->loadObjectList();
// Many records
//echo '<pre>';
//print_r($products);
//echo '</pre>';
//$std = new stdClass();
//$std->name = 'Samir';
//$arr['name'] = 'Samir';
########################################################
// For one record loadObject();
// For one value loadResult();
// Get product_id = 8
$query = 'select * from aca_product where product_id = 8';
$db->setQuery($query);
$product = $db->loadObject();
echo '<h1>' . $product->name . '</h1>';
echo '<h3>' . $product->price . '</h3>';
echo '<img src="' . $product->image . '"/>';
$query = 'select price from aca_product limit 1';
$db->setQuery($query);
$price = $db->loadResult();
echo '$price=' . $price . '<br/>';
$query = 'select count(*) from aca_product';
$db->setQuery($query);