PHP Classes

Abstraction

Recommend this page to a friend!

      Simple DAL  >  All threads  >  Abstraction  >  (Un) Subscribe thread alerts  
Subject:Abstraction
Summary:How is it an abstraction layer?
Messages:6
Author:rudie dirkx
Date:2012-02-11 12:36:27
Update:2012-02-12 20:12:28
 

  1. Abstraction   Reply   Report abuse  
Picture of rudie dirkx rudie dirkx - 2012-02-11 12:36:27
How is it an **abstraction** layer if you're calling `mysql_fetch_assoc` in the model?

From `EmployeeDAL.php`. This part is abstract:

$result = $this->conn->executeQuery($qry);

But the next line is **very** specific:

while ($row = mysql_fetch_assoc($result))

`$result` should have been abstract as well.

My DAL/DBAL does that: https://github.com/rudiedirkx/db_generic It separates dev logic entirely from databse engine logic. `db_generic->fetch()`, `db_generic->select()` etc return a `db_generic_result` object which (is iterable and) contains methods like `nextObject()`.

Just saying. The models are good. But it's not abstract.

  2. Re: Abstraction   Reply   Report abuse  
Picture of halguien halguien - 2012-02-11 22:28:49 - In reply to message 1 from rudie dirkx
bueno, parece que hay un pequeño detalle en el archivo employee_detail.php

En el archivo original está esto en el script del principio del documento:

if ($isEditing) {
$assignedSuppliers = $employeeDal->getSuppliersForEmployee($employeeId);
$employeeDetail = $employeeDal->getEmployeeDetail($employeeId);
}

y el formulario en los campos figura esto:

<input id="name" name="name" type="text" value="<?php $employeeDetail['Name']; ?>"/>

el problema es que de esa forma da ERRORES porque las variables no están definidas y por tanto nunca va a imprimir el valor de las variables

lo que hice fué quitar todo esto del script en el principio del documento:

$employeeDetail = array();
if ($isEditing) {
$assignedSuppliers = $employeeDal->getSuppliersForEmployee($employeeId);
$employeeDetail = $employeeDal->getEmployeeDetail($employeeId);
}

y poner lo siguiente en los inputs:

<input id="name" name="name" type="text" value="<?php if ($isEditing) {
$assignedSuppliers = $employeeDal->getSuppliersForEmployee($employeeId);
$employeeDetail = $employeeDal->getEmployeeDetail($employeeId);
echo $employeeDetail['Name'];
} ?>"/>

de esa forma solo muestra los valores en el input si es que uno va a hacer un upgrade, de lo contrario no muestra nada y tampoco muestra errores de que no encuentra las variables...

bueno, espero haber sido claro en esto porque suelo enredarme un poco


  3. Re: Abstraction   Reply   Report abuse  
Picture of Shibly Shibly - 2012-02-12 09:27:53 - In reply to message 1 from rudie dirkx
Thank you for using my script. Yes you are right. But I've only used mysql related function here to manipulate the database. The class is "MysqlConnection.php" . and I make an instance of this class in "DBConnection.php" . The "DBConnection.php" has a static method which calls the instance class. As you know that you can not directly call an abstract class. BUT you can call a static method inside it :) . The way I implemented the mysql abstraction in "MysqlConnection.php" , you can create your own database specific class like "mysqlite.php" and instantiate it inside the "MysqlConnection.php" by using it's static method. Thank you a lot .

  4. Re: Abstraction   Reply   Report abuse  
Picture of Shibly Shibly - 2012-02-12 09:29:37 - In reply to message 2 from halguien
Please check the latest update. I guess It solves the errors now . Thank you .

  5. Re: Abstraction   Reply   Report abuse  
Picture of halguien halguien - 2012-02-12 15:22:19 - In reply to message 4 from Shibly
in employee_detail.php at the entrance where it gets the value of "basic salary" (without writing any value) points as valid?

Thanks for the update!!

  6. Re: Abstraction   Reply   Report abuse  
Picture of Shibly Shibly - 2012-02-12 20:12:28 - In reply to message 5 from halguien
Hi,

Actually the main concern of this script is how to make a database abstraction layer :) and keep the database specific query separate. Well I guess I've missed some validation rules. Will check that later. Thank you for your reply :)