Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18250
| Newsgroups | comp.lang.php |
|---|---|
| Date | 2020-03-20 05:13 -0700 |
| References | <bb6ab77d-df8a-49e5-bd79-a467cf81ae57@googlegroups.com> |
| Message-ID | <32d5f2ce-8faa-4580-92e8-da3d0141987a@googlegroups.com> (permalink) |
| Subject | Re: Looking for relational database programmed in PHP |
| From | Kristjan Robam <robamman2020@hotmail.com> |
Added functions:
<?php
class Myobj {
public $a;
public $a2;
public function getNameOfClass()
{
return static::class;
}
}
class Myobj2 {
public $a2;
public $a3;
public function getNameOfClass()
{
return static::class;
}
}
class Easyphpdb {
private $dbtables;
function setvalue($a) {
$this->dbtables=$a;
}
function getvalue() {
return $this->dbtables;
}
function saveobjecttable($obj, $name) {
if (file_exists($name)) {
return false;
}
$b=serialize($obj);
$fh = fopen($name.".edb", "a");
fwrite($fh, $b);
fclose($fh);
return true;
}
function loadobjecttables() {
$dbtables = array();
foreach (glob("*.edb") as $file) {
$file1 = file_get_contents($file, true);
$dbtables[] = unserialize($file1);
}
$this->setvalue($dbtables);
}
function deleteotable($otabname) {
unlink($otabname.".edb");
loadobjecttables();
}
function insertobject($obj) {
loadobjecttables();
$oclass=$obj->getNameOfClass();
$tabls=$this->getvalue();
$oarridx=null;
for($i=0; $i<count($tabls); $i++) {
if($tabls[$i][0]->getNameOfClass().".edb"==$oclass) {
$oarridx=$i;
}
}
if($oarridx==null) return false;
$tabls[$oarridx][]=$obj;
unlink($tabls[$oarridx][0]->getNameOfClass().".edb");
$b=serialize($$tabls[$oarridx]);
$fh = fopen($tabls[$oarridx][0]->getNameOfClass().".edb", "a");
fwrite($fh, $b);
fclose($fh);
}
function convertObjectClass($objectA,
$objectB) {
$new_object = array();
// Initializing class properties
foreach($objectA as $property => $value) {
$new_object[$property]=$value;
}
foreach($objectB as $property => $value) {
$new_object[$property]=$value;
}
return $new_object;
}
function query($query) {
$this->loadobjecttables();
$ovars=array();
$objects=$this->getvalue();
for($i=0; $i<count($objects); $i++) {
$ovars[]=array_keys(get_object_vars($objects[$i][0]));
}
$mches=false;
$results=null;
for($i=0; $i<count($objects); $i++) {
for($j=0; $j<count($ovars); $j++) {
if(preg_match("/^select ".$ovars[$i][$j]." from ".$objects[$i][0]->getNameOfClass().";$/",$query)) {
return array_column($objects[$i], $ovars[$i][$j]);
$mches=true;
break;
}
}
}
for($i=0; $i<count($objects); $i++) {
for($j=0; $j<count($ovars); $j++) {
for($k=0; $k<count($objects); $k++) {
for($l=0; $l<count($ovars); $l++) {
if(preg_match("/^select \* from ".$objects[$i][0]->getNameOfClass()." join ".$objects[$k][0]->getNameOfClass()." on \(".$objects[$i][0]->getNameOfClass()."\.".$ovars[$i][$j]."\=".$objects[$k][0]->getNameOfClass()."\.".$ovars[$k][$l]."\);$/",$query)) {
$outp=array();
$oobj = $this->convertObjectClass($objects[$i][0], $objects[$k][0]);
//print_r($obj_merged);
$outp[]=$oobj;
return $outp;
}
$mches=true;
break;
}
}
}
}
return $mches;
}
}
$aone=array();
$a1=new Myobj();
$a1->a="11111";
$a1->a2="22222";
$aone[]=$a1;
$a1=new Myobj();
$a1->a="33333";
$a1->a2="44444";
$aone[]=$a1;
$atwo=array();
$a1=new Myobj2();
$a1->a2="22222";
$a1->a3="12345";
$atwo[]=$a1;
$a1=new Myobj2();
$a1->a2="44444";
$a1->a3="67890";
$atwo[]=$a1;
$mydb=new Easyphpdb();
//$mydb->saveobjecttable($aone, "Myobj");
//$mydb->saveobjecttable($atwo, "Myobj2");
//print_r($mydb->query("select a from Myobj;"));
//print_r($mydb->query("select a2 from Myobj2;"));
//print_r($mydb->query("select * from Myobj join Myobj2 on (Myobj.a2=Myobj2.a2);"));
?>
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-19 08:10 -0800
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2019-12-19 12:30 -0500
Re: Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-19 14:33 -0800
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2019-12-19 17:49 -0500
Re: Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-20 09:37 -0800
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2019-12-20 16:51 -0500
Re: Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-21 05:25 -0800
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2019-12-21 17:48 -0500
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2019@gmail.com> - 2019-12-22 00:20 -0800
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2019-12-22 10:05 -0500
Re: Looking for relational database programmed in PHP Arno Welzel <usenet@arnowelzel.de> - 2019-12-22 18:04 +0100
Re: Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-22 10:10 -0800
Re: Looking for relational database programmed in PHP "J.O. Aho" <user@example.net> - 2019-12-20 07:21 +0100
Re: Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-20 09:44 -0800
Re: Looking for relational database programmed in PHP "J.O. Aho" <user@example.net> - 2019-12-20 20:28 +0100
Re: Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-21 05:20 -0800
Re: Looking for relational database programmed in PHP "J.O. Aho" <user@example.net> - 2019-12-22 15:35 +0100
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2019-12-21 17:50 -0500
Re: Looking for relational database programmed in PHP robamman2019@gmail.com - 2019-12-22 00:24 -0800
Re: Looking for relational database programmed in PHP kristjanise129@gmail.com - 2020-03-13 09:50 -0700
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2020-03-13 14:33 -0400
Re: Looking for relational database programmed in PHP kristjanise129@gmail.com - 2020-03-13 11:58 -0700
Re: Looking for relational database programmed in PHP "J.O. Aho" <user@example.net> - 2020-03-13 20:09 +0100
Re: Looking for relational database programmed in PHP robamman2020@hotmail.com - 2020-03-13 23:02 -0700
Re: Looking for relational database programmed in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2020-03-13 18:19 -0400
Re: Looking for relational database programmed in PHP robamman2020@hotmail.com - 2020-03-13 23:04 -0700
Re: Looking for relational database programmed in PHP Arno Welzel <usenet@arnowelzel.de> - 2020-03-14 13:21 +0100
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-14 09:26 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-19 11:43 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-19 13:16 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-20 02:31 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-20 05:13 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-20 08:09 -0700
Includable simple object based relational php database, that saves data to files and uses only 1 file (the database system php file) Kristjan Robam <robamman2020@hotmail.com> - 2020-03-21 11:45 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-21 23:29 -0700
Simple object based php database system, that saves data to files and needs only 1 php file(the system php file) Kristjan Robam <robamman2020@hotmail.com> - 2020-03-24 09:06 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-24 22:46 -0700
Re: Looking for relational database programmed in PHP Kristjan Robam <robamman2020@hotmail.com> - 2020-03-26 01:16 -0700
Re: Looking for relational database programmed in PHP robamman2020@hotmail.com - 2020-03-28 08:21 -0700
Re: Looking for relational database programmed in PHP Luuk <luuk34@gmail.com> - 2020-03-28 17:39 +0100
Re: Simple object based relational database system, that saves data to files and is includable(php file) robamman2020@hotmail.com - 2020-03-29 08:46 -0700
Re: Simple object based relational php database system, that saves data to files and is includable(php file) robamman2020@hotmail.com - 2020-03-29 08:52 -0700
Re: Simple object based relational php database system, that saves data to files and is includable(php file) Luuk <luuk34@gmail.com> - 2020-03-30 20:02 +0200
Re: Simple object based relational php database system, that saves data to files and is includable(php file) Allodoxaphobia <trepidation@example.net> - 2020-04-01 02:49 +0000
Re: Simple object based relational php database system, that saves data to files and is includable(php file) robamman2020@hotmail.com - 2020-03-31 23:16 -0700
Re: Simple object based relational php database system, that saves data to files and is includable(php file) Arno Welzel <usenet@arnowelzel.de> - 2020-04-01 16:47 +0200
Re: Simple object based relational database system, that saves data to files and is includable(php file) Jim H <invalid@invalid.invalid> - 2020-03-30 18:16 +0000
Re: Simple object based relational database system, that saves data to files and is includable(php file) Arno Welzel <usenet@arnowelzel.de> - 2020-03-31 11:59 +0200
Re: Simple object based relational database system, that saves data to files and is includable(php file) robamman2020@hotmail.com - 2020-03-31 23:15 -0700
Re: Simple object based relational database system, that saves data to files and is includable(php file) Arno Welzel <usenet@arnowelzel.de> - 2020-04-01 16:48 +0200
Re: Simple object based database system, that saves data to files and is includable(php file) robamman2020@hotmail.com - 2020-04-01 10:03 -0700
csiph-web