Example #1
0
 public function createNewObject(array $params)
 {
     if (empty($params)) {
         throw new \Exception('Empty params passed to create the object');
     }
     //todo - pass the params to sub handler and it will take care of this
     $objectTypeId = $params[StorouConstants::KEY_OBJECT_TYPE_ID_INT];
     $title = $params[StorouConstants::KEY_TITLE_STRING];
     $content = $params[StorouConstants::KEY_CONTENT_STRING];
     $createdBy = $params[StorouConstants::KEY_CREATED_BY_INT];
     $createdOn = $params[StorouConstants::KEY_CREATED_ON_DATE];
     $updatedOn = $params[StorouConstants::KEY_UPDATED_ON_DATE];
     $status = $params[StorouConstants::KEY_STATUS_INT];
     $parentObjectId = isset($params[StorouConstants::KEY_PARENT_OBJECT_ID_INT]) ? $params[StorouConstants::KEY_PARENT_OBJECT_ID_INT] : 0;
     $query = 'INSERT INTO objects (objectTypeId,title,content,createdBy,createdOn,createdOn,parentObjectId,status) VALUES (?,?,?,?,?,?)';
     $params = array($objectTypeId, $title, $content, $createdBy, $createdOn, $updatedOn, $parentObjectId, $status);
     if ($parentObjectId > 0) {
         $query = 'INSERT INTO objects (objectTypeId,title,content,createdBy,createdOn,status,parentObjectId) VALUES (?,?,?,?,?)';
         $params[] = $parentObjectId;
     }
     $objId = DbConnection::getConnection()->insertUpdateData($query, $params);
     /*
      * TODO: Update revisions
      */
     return $objId;
 }
Example #2
0
 /**
  * @expectedException \PDOException
  */
 public function testThrowsPdoException()
 {
     $sDsn = 'invalidDsn';
     $aValidParams = ['dbal_user' => 'john', 'dbal_password' => 'secret'];
     /** @var DbDriverManager $manager */
     $manager = $this->prophesize('vaidasif\\dbal\\DbDriverManager');
     $manager->prepareDsn($aValidParams)->willReturn($sDsn);
     $obj = new DbConnection($aValidParams);
     $obj->setDbDriverManager($manager->reveal());
     $obj->getConnection();
 }
 function Get_Category_Name()
 {
     DbConnection::getConnection();
     $sql = "Select ctg_name FROM category where ctg_id='" . $_POST["ctg_id"] . "'";
     if (DbConnection::getConnection()->query($sql) === TRUE) {
         echo "Query success";
         $result = DbConnection::getConnection()->query($sql);
         if ($result->num_rows > 0) {
             // output data of each row
             while ($row = $result->fetch_assoc()) {
                 return $row["ctg_name"];
             }
         } else {
             return 0;
         }
     } else {
         echo "Error: " . $sql . "<br>" . DbConnection::getConnection()->query($sql)->error;
     }
 }
    <thead>
      <tr>
        <th>Name</th>
        <th>Room</th>
        <th>image</th>
        <th>Ext.</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
       <?php 
echo '<form role="form" action="../models/edituser.php?id=' . $_GET['id'] . '" method="post" enctype="multipart/form-data">';
echo "<div class='form-group'>";
require_once "../controllers/DbConnection.php";
require_once "../controllers/user.php";
$pro = new user(DbConnection::getConnection());
$result = $pro->search_user($_GET['id']);
if ($result->num_rows == 1) {
    while ($row = $result->fetch_assoc()) {
        echo "<tr> <td>\n                               <input class='form-control' value='" . $row["u_name"] . "'\n                               type='text' name='u_name'> </td>";
        echo "<td> <input class='form-control' value='" . $row["room_no"] . "'\n                               type='text' name='room_no'>\n                               </td>";
        echo "<td> <input class='form-control' name='pic' type='file' value='/img/" . $row['u_img'] . "' width='30' height='30'/></td>";
        echo "<td> <input class='form-control' name='ext' value='" . $row["ext"] . "' </td> ";
        echo "<td> <button type='submit'>Submit</button> </td> </tr> ";
    }
}
?>
  
       
    </tbody>
   </form> 
$result = $pro->Search_product($_GET['id']);
if ($result->num_rows == 1) {
    // output data of each row
    while ($row = $result->fetch_assoc()) {
        // echo "<option value='".$row["ctg_id"]."'>".$row["ctg_name"]."</option>";
        echo "<label class='control-label' >Product</label>";
        echo "<input class='form-control' id='product' value='" . $row["p_name"] . "'\n                               type='text' name='p_name'>";
        echo "</div>";
        echo "<div class='form-group'>";
        echo " <label class='control-label'>Price</label>";
        echo "<input class='form-control' id='price' type='number' min='0'\n                               value='" . $row["u_price"] . "' name='u_price'>";
    }
}
echo "</div>";
echo "<div class='form-group'>\n                        <a href='../views/Add_Category.html' class='pull-right'>Add Category</a>\n                        <label class='control-label' for='category'>Category</label>\n                        <select name='ctg_id' class='form-control' id='category' >\n                            <option value='' selected=''>Select Category</option>\n                          ";
$pro = new Category(DbConnection::getConnection());
$result = $pro->select_categories();
if ($result->num_rows > 0) {
    // output data of each row
    while ($row = $result->fetch_assoc()) {
        echo "<option value='" . $row["ctg_id"] . "'>" . $row["ctg_name"] . "</option>";
    }
} else {
    echo "0 results";
}
echo "</select>";
echo " <div >";
echo "    <label class='control-label'>Select Image</label>";
echo "<input name='p_img' type='file' class='control-label' id='img'>";
echo "</div>";
echo "<br/>";
     echo '{"status":"fail", "message":"Password or confirm password fields cannot be empty."}';
 } elseif (empty($email)) {
     header("HTTP/1.0 401 Invalid submitted data");
     echo '{"status":"fail", "message":"Email field cannot be empty, or it is not a valid email address"}';
 } elseif ($password !== $pwdConfirm) {
     header("HTTP/1.0 401 Invalid submitted data");
     echo '{"status":"fail","message":"Passwords donot match."}';
 } elseif (strlen($password) < 7) {
     header("HTTP/1.0 401 Invalid submitted data");
     echo '{"status":"fail", "message":"Passwords should be at least 7 characters long."}';
 } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
     header("HTTP/1.0 401 Invalid submitted data");
     echo '{"status":"fail", "message":"Please input valid email address!"}';
 } elseif ($db->isConnected()) {
     // let's make sure user doesn't exists
     $pdo = $db->getConnection();
     $query = $pdo->prepare("SELECT user_name from users WHERE user_name = :username");
     $query->bindValue(':username', $username, PDO::PARAM_STR);
     $query->execute();
     $result = $query->fetchAll();
     if (count($result) > 0 || count($errors) > 0) {
         header("HTTP/1.0 401 Invalid submitted data");
         echo '{"status":"fail", "message":"Please make sure your password or username are valids"}';
         //json_encode($errors);
     } else {
         // check to see if we don't have errors
         try {
             $options = ['cost' => 12];
             $user_password_hash = password_hash($password, PASSWORD_BCRYPT, $options);
             $new_user = $pdo->prepare("INSERT INTO users (user_name, user_password_hash, user_email, user_registration_datetime) VALUES (:username, :user_password_hash, :email, NOW())");
             $new_user->bindValue(':username', $username, PDO::PARAM_STR);
 public function get_PName()
 {
     $sql = "Select p_name FROM products where p_id='" . $_POST["p_id"] . "'";
     if ($this->dbConnection->query($sql)->query($sql) === TRUE) {
         echo "Query success";
         $result = $this->dbConnection->query($sql)->query($sql);
         if ($result->num_rows > 0) {
             // output data of each row
             while ($row = $result->fetch_assoc()) {
                 return $row["p_name"];
             }
         } else {
             return 0;
         }
     } else {
         echo "Error: " . $sql . "<br>" . DbConnection::getConnection()->query($sql)->error;
     }
 }
<?php

require_once "../controllers/DbConnection.php";
require_once "../controllers/Product.php";
$pro = new Product(DbConnection::getConnection());
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$upfile = "../assets/img/" . $_FILES['p_img']['name'];
// Does the file have the right MIME type?
if (!($_FILES['p_img']['type'] == "image/jpg" or $_FILES['p_img']['type'] == "image/gif" or $_FILES['p_img']['type'] == "image/jpeg" or $_FILES['p_img']['type'] == "image/png")) {
    header("Location: ../views/EditProduct.php");
}
if (is_uploaded_file($_FILES['p_img']['tmp_name'])) {
    if (!move_uploaded_file($_FILES['p_img']['tmp_name'], $upfile)) {
        echo 'Problem: Could not move file to destination directory';
    } else {
        echo 'Problem: Possible file upload attack. Filename: ';
        echo $_FILES['p_img']['name'];
    }
    //echo 'File uploaded successfully<br><br>';
}
$result = $pro->update_product($_GET["id"], $_POST["p_name"], $_POST["u_price"], $_POST["ctg_id"], $_FILES['p_img']['name']);
header("Location: ../views/Show_Products.php");
<?php

require_once "DbConnection.php";
session_start();
$productsInterface = DbConnection::getConnection();
if (isset($_POST['dest'])) {
    switch ($_POST['dest']) {
        case 'getProducts':
            $productsSet = $productsInterface->query('select * from products where status != 0');
            $products = array();
            while ($product = $productsSet->fetch_assoc()) {
                array_push($products, $product);
            }
            echo json_encode($products);
            break;
        case 'getLatestProducts':
            // need to be dynamic and use dynamic user id
            $productsSet = $productsInterface->query("SELECT products. * , orders.u_id, orders.date,\n\t\t\t\t\torders.time FROM products, orders, orders_details WHERE orders.o_id = orders_details\n\t\t\t\t\t.o_id AND products.p_id = orders_details.p_id AND orders.u_id =3 ORDER BY \n\t\t\t\t\torders.date DESC LIMIT 3");
            $products = array();
            while ($product = $productsSet->fetch_assoc()) {
                array_push($products, $product);
            }
            echo json_encode($products);
            break;
        case 'searchProducts':
            $productsSet = $productsInterface->query("select * from products where p_name like '" . $_POST['query'] . "%'");
            $products = array();
            while ($product = $productsSet->fetch_assoc()) {
                array_push($products, $product);
            }
            echo json_encode($products);
<?php

header("Content-Type: text/event-stream");
header("Cache-Control: no-cache");
// header('retry: 1000');
require_once "DbConnection.php";
require_once "../models/Orders.php";
session_start();
if (!isset($_SESSION['rows'])) {
    $_SESSION['rows'] = 0;
}
var_dump($_SESSION);
$tblRows = $_SESSION['rows'];
$dbConnection = DbConnection::getConnection();
$orderInterface = new Orders($dbConnection);
$dbRowSet = $dbConnection->query("SELECT count(*) as count from orders");
$resultArr = $dbRowSet->fetch_assoc();
// $resultArr = json_encode($resultArr);
// echo "data: {$resultArr}\n\n";
if ($tblRows != 0 && $tblRows < $resultArr['count']) {
    $_SESSION['rows'] = $resultArr['count'];
    $ordersSet = $orderInterface->getOrders("and status != 'canceled' order by date,time desc limit 1");
    $order = $ordersSet->fetch_assoc();
    $response = array();
    $response['response'] = $order;
    $response = json_encode($response);
    echo "data: {$response}\n\n";
    ob_end_flush();
    flush();
} else {
    $_SESSION['rows'] = $resultArr['count'];
<?php

require_once "DbConnection.php";
session_start();
$usersInterface = DbConnection::getConnection();
if (isset($_POST['dest'])) {
    switch ($_POST['dest']) {
        case 'getUsers':
            $usersSet = $usersInterface->query("select * from users");
            $users = array();
            while ($user = $usersSet->fetch_assoc()) {
                array_push($users, $user);
            }
            echo json_encode($users);
            break;
        case 'getUsersTotal':
            $usersTotalSet = $usersInterface->query("select users.u_id,users.u_name,sum(orders.total_price) as user_total from users,orders where users.u_id = orders.u_id and orders.status != 'canceled' group by users.u_name order by user_total desc");
            $usersTotal = array();
            while ($userTotal = $usersTotalSet->fetch_assoc()) {
                array_push($usersTotal, $userTotal);
            }
            echo json_encode($usersTotal);
            break;
        case 'getChecksRange':
            $usersTotalSet = $usersInterface->query("select users.u_id,users.u_name,sum(orders.total_price) as user_total from users,orders where users.u_id = orders.u_id and orders.status != 'canceled' and orders.date between '" . $_POST['from'] . "' and \n                    '" . $_POST['to'] . "' group by users.u_name order by user_total desc");
            $usersTotal = array();
            while ($userTotal = $usersTotalSet->fetch_assoc()) {
                array_push($usersTotal, $userTotal);
            }
            echo json_encode($usersTotal);
            break;
Example #12
0
/**
 * Created by IntelliJ IDEA.
 * User: tueda
 * Date: 15/09/22
 * Time: 15:27
 */
include_once __DIR__ . "/env.php";
require_once SRC_PATH . "/etc/DbConfig.php";
require_once SRC_PATH . "/common/ClassLoader.php";
ClassLoader::addPath(array(LIBRARY_PATH . '/' . DbConfig::$DB_ROW, LIBRARY_PATH . '/' . DbConfig::$DB_QUERY, LIBRARY_PATH . '/' . DbConfig::$DB_EXCEPTION, SRC_PATH . '/' . DbConfig::$DB_ETC, SRC_PATH . '/' . DbConfig::$DB_COMMON, SRC_PATH . '/' . DbConfig::$DB_SAMPLE));
spl_autoload_register(array('ClassLoader', '_autoLoad'));
try {
    $dbh = new DbConnection();
    $mysqlnd = function_exists('mysqli_fetch_all');
    if ($mysqlnd) {
        print "mysqlnd enabled!" . "\n";
    }
    $clver = $dbh->getConnection()->getAttribute(PDO::ATTR_CLIENT_VERSION);
    if (strpos($clver, 'mysqlnd') !== false) {
        print "PDO MySQLnd enabled! : " . $clver . "\n";
    }
    $ite = new SimpleBlancoSelectAllIterator($dbh->getConnection());
    $ite->prepareStatement();
    $stmt = $ite->getStatement();
    while ($ite->next()) {
        $row = $ite->getRow();
        print $row . "\n";
    }
} catch (Exception $e) {
    print $e . "\n";
}