note 79473 deleted from function.mysql-query by sp
| From: | sp@php.net | Date: | Sat, 24 May 2008 20:54:03 +0000 |
| Subject: | note 79473 deleted from function.mysql-query by sp | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139708@lists.php.net to get a copy of this message | ||
Note Submitter: gemegemes at NOSPAM dot gmail dot com
----
Hi Im L, In a big application, you can't avoid multiple mysql queries and the possible problem
of this it can lead your application to misfunction. Here's a reusable code and the minimal
answer to the problem.
<?php
class Select
{
// subclass query mysql using
// select
function exe($sql)
{
$exe = mysql_query($sql);
return $exe;
}
}
class Insert
{
// subclass query mysql using
// insert
function exe($sql)
{
$exe = mysql_query($sql);
return $exe;
}
}
class Update
{
// subclass query mysql using
// update
function exe($sql)
{
$exe = mysql_query($sql);
return $exe;
}
}
// You can define more subclasses here for fetch array,
// delete, Join etc..
class Controller
{
// main class which load
// the subclasses
var $control;
// load the subclass
function Controller($control)
{
eval("\$this->control = new $control;");
}
function exe($sql)
{
$this->control->exe($sql);
}
}
?>
Usage Example:
<?php
$Select=new Controller('Select');
$Select->exe(SELECT * FROM table .....);
$Insert=new Controller('Insert');
$Insert->exe(INSERT INTO table ......);
$Update=new Controller('Update');
$Update->exe(UPDATE table SET .....);
?>