Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18116 > unrolled thread

Looking for relational database programmed in PHP

Started byrobamman2019@gmail.com
First post2019-12-19 08:10 -0800
Last post2020-04-01 10:03 -0700
Articles 20 on this page of 51 — 11 participants

Back to article view | Back to comp.lang.php


Contents

  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

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#18235

FromJerry Stuckle <jstucklex@attglobal.net>
Date2020-03-13 14:33 -0400
Message-ID<r4gjlv$gg8$1@jstuckle.eternal-september.org>
In reply to#18234
On 3/13/2020 12:50 PM, kristjanise129@gmail.com wrote:
> I am asking anyway.
> Is somebody found this kind of database from web?
> 
> I would really appreciate it.
> I am gonna search it myself too now...
> But the faster I get the answer, the better it is...
> 
> 
> With best regards,
> Kristjan Robam
> 

The answer hasn't changed.

The code for a relational database is huge and complicated.  Look at the 
MariaDB daemon (version 10.3.17 on Linux), for instance - over 20MB of 
compiled C code just for that one program.  PHP is not at all suited for 
such a project.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#18236

Fromkristjanise129@gmail.com
Date2020-03-13 11:58 -0700
Message-ID<21b64251-3fe4-43ab-bf43-7664f0657b70@googlegroups.com>
In reply to#18235
reede, 13. märts 2020 20:33.41 UTC+2 kirjutas Jerry Stuckle:
> On 3/13/2020 12:50 PM, kristjanise129@gmail.com wrote:
> > I am asking anyway.
> > Is somebody found this kind of database from web?
> > 
> > I would really appreciate it.
> > I am gonna search it myself too now...
> > But the faster I get the answer, the better it is...
> > 
> > 
> > With best regards,
> > Kristjan Robam
> > 
> 
> The answer hasn't changed.
> 
> The code for a relational database is huge and complicated.  Look at the 
> MariaDB daemon (version 10.3.17 on Linux), for instance - over 20MB of 
> compiled C code just for that one program.  PHP is not at all suited for 
> such a project.
> 
> -- 
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================


http : // gladius . sourceforge . net / install . php

Seems like just what I needed. 

Size is 166KB unpacked.

First steps:

  include 'gladius.php';
  
  $G = new Gladius();
  
  $G->SetDBRoot('path/to/database_directories') or die;
  
  $G->SelectDB('db_directory_or_path_to_db');
  
  $G->Query('CREATE TABLE mytable ( id int auto_increment NOT NULL PRIMARY_KEY, name VARCHAR(30) NOT NULL, phonenr varchar(20))');



Interesting that noone found it before me !


K

[toc] | [prev] | [next] | [standalone]


#18238

From"J.O. Aho" <user@example.net>
Date2020-03-13 20:09 +0100
Message-ID<hd242eF5n5U1@mid.individual.net>
In reply to#18236
On 13/03/2020 19.58, kristjanise129@gmail.com wrote:
> reede, 13. märts 2020 20:33.41 UTC+2 kirjutas Jerry Stuckle:
>> On 3/13/2020 12:50 PM, kristjanise129@gmail.com wrote:
>>> I am asking anyway.
>>> Is somebody found this kind of database from web?
>>>
>>> I would really appreciate it.
>>> I am gonna search it myself too now...
>>> But the faster I get the answer, the better it is...
>>>
>>>
>>> With best regards,
>>> Kristjan Robam
>>>
>>
>> The answer hasn't changed.
>>
>> The code for a relational database is huge and complicated.  Look at the
>> MariaDB daemon (version 10.3.17 on Linux), for instance - over 20MB of
>> compiled C code just for that one program.  PHP is not at all suited for
>> such a project.
>>
>> -- 
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> jstucklex@attglobal.net
>> ==================
> 
> 
> http : // gladius . sourceforge . net / install . php
> 
> Seems like just what I needed.
> 
> Size is 166KB unpacked.
> 
> First steps:
> 
>    include 'gladius.php';
>    
>    $G = new Gladius();
>    
>    $G->SetDBRoot('path/to/database_directories') or die;
>    
>    $G->SelectDB('db_directory_or_path_to_db');
>    
>    $G->Query('CREATE TABLE mytable ( id int auto_increment NOT NULL PRIMARY_KEY, name VARCHAR(30) NOT NULL, phonenr varchar(20))');

Do not use joins, you will get the wrong number of rows returned, think 
this bug been around since 2007, but then there not been updates since 2009.

-- 

  //Aho

[toc] | [prev] | [next] | [standalone]


#18240

Fromrobamman2020@hotmail.com
Date2020-03-13 23:02 -0700
Message-ID<2e0525cf-5bd2-4223-a728-8cff6ab6949f@googlegroups.com>
In reply to#18238
reede, 13. märts 2020 21:09.09 UTC+2 kirjutas J.O. Aho:
> On 13/03/2020 19.58, kristjanise129@gmail.com wrote:
> > reede, 13. märts 2020 20:33.41 UTC+2 kirjutas Jerry Stuckle:
> >> On 3/13/2020 12:50 PM, kristjanise129@gmail.com wrote:
> >>> I am asking anyway.
> >>> Is somebody found this kind of database from web?
> >>>
> >>> I would really appreciate it.
> >>> I am gonna search it myself too now...
> >>> But the faster I get the answer, the better it is...
> >>>
> >>>
> >>> With best regards,
> >>> Kristjan Robam
> >>>
> >>
> >> The answer hasn't changed.
> >>
> >> The code for a relational database is huge and complicated.  Look at the
> >> MariaDB daemon (version 10.3.17 on Linux), for instance - over 20MB of
> >> compiled C code just for that one program.  PHP is not at all suited for
> >> such a project.
> >>
> >> -- 
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> jstucklex@attglobal.net
> >> ==================
> > 
> > 
> > http : // gladius . sourceforge . net / install . php
> > 
> > Seems like just what I needed.
> > 
> > Size is 166KB unpacked.
> > 
> > First steps:
> > 
> >    include 'gladius.php';
> >    
> >    $G = new Gladius();
> >    
> >    $G->SetDBRoot('path/to/database_directories') or die;
> >    
> >    $G->SelectDB('db_directory_or_path_to_db');
> >    
> >    $G->Query('CREATE TABLE mytable ( id int auto_increment NOT NULL PRIMARY_KEY, name VARCHAR(30) NOT NULL, phonenr varchar(20))');
> 
> Do not use joins, you will get the wrong number of rows returned, think 
> this bug been around since 2007, but then there not been updates since 2009.
> 
> -- 
> 
>   //Aho

Ok.

[toc] | [prev] | [next] | [standalone]


#18239

FromJerry Stuckle <jstucklex@attglobal.net>
Date2020-03-13 18:19 -0400
Message-ID<r4h0sr$dr0$1@jstuckle.eternal-september.org>
In reply to#18236
On 3/13/2020 2:58 PM, kristjanise129@gmail.com wrote:
> reede, 13. märts 2020 20:33.41 UTC+2 kirjutas Jerry Stuckle:
>> On 3/13/2020 12:50 PM, kristjanise129@gmail.com wrote:
>>> I am asking anyway.
>>> Is somebody found this kind of database from web?
>>>
>>> I would really appreciate it.
>>> I am gonna search it myself too now...
>>> But the faster I get the answer, the better it is...
>>>
>>>
>>> With best regards,
>>> Kristjan Robam
>>>
>>
>> The answer hasn't changed.
>>
>> The code for a relational database is huge and complicated.  Look at the
>> MariaDB daemon (version 10.3.17 on Linux), for instance - over 20MB of
>> compiled C code just for that one program.  PHP is not at all suited for
>> such a project.
>>
>> -- 
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> jstucklex@attglobal.net
>> ==================
> 
> 
> http : // gladius . sourceforge . net / install . php
> 
> Seems like just what I needed.
> 
> Size is 166KB unpacked.
> 
> First steps:
> 
>    include 'gladius.php';
>    
>    $G = new Gladius();
>    
>    $G->SetDBRoot('path/to/database_directories') or die;
>    
>    $G->SelectDB('db_directory_or_path_to_db');
>    
>    $G->Query('CREATE TABLE mytable ( id int auto_increment NOT NULL PRIMARY_KEY, name VARCHAR(30) NOT NULL, phonenr varchar(20))');
> 
> 
> 
> Interesting that noone found it before me !
> 
> 
> K
> 

It's a flatfile database, not relational, and only uses a small subset 
of the SQL language.  It also has never had a release version - beta is 
as far as it ever got.  And it has been abandoned for over 5 years.

Not what I would call useful.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#18241

Fromrobamman2020@hotmail.com
Date2020-03-13 23:04 -0700
Message-ID<c4e6c566-39ba-42a7-9d14-d1d8233d72da@googlegroups.com>
In reply to#18239
laupäev, 14. märts 2020 0:19.12 UTC+2 kirjutas Jerry Stuckle:
> On 3/13/2020 2:58 PM, kristjanise129@gmail.com wrote:
> > reede, 13. märts 2020 20:33.41 UTC+2 kirjutas Jerry Stuckle:
> >> On 3/13/2020 12:50 PM, kristjanise129@gmail.com wrote:
> >>> I am asking anyway.
> >>> Is somebody found this kind of database from web?
> >>>
> >>> I would really appreciate it.
> >>> I am gonna search it myself too now...
> >>> But the faster I get the answer, the better it is...
> >>>
> >>>
> >>> With best regards,
> >>> Kristjan Robam
> >>>
> >>
> >> The answer hasn't changed.
> >>
> >> The code for a relational database is huge and complicated.  Look at the
> >> MariaDB daemon (version 10.3.17 on Linux), for instance - over 20MB of
> >> compiled C code just for that one program.  PHP is not at all suited for
> >> such a project.
> >>
> >> -- 
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> jstucklex@attglobal.net
> >> ==================
> > 
> > 
> > http : // gladius . sourceforge . net / install . php
> > 
> > Seems like just what I needed.
> > 
> > Size is 166KB unpacked.
> > 
> > First steps:
> > 
> >    include 'gladius.php';
> >    
> >    $G = new Gladius();
> >    
> >    $G->SetDBRoot('path/to/database_directories') or die;
> >    
> >    $G->SelectDB('db_directory_or_path_to_db');
> >    
> >    $G->Query('CREATE TABLE mytable ( id int auto_increment NOT NULL PRIMARY_KEY, name VARCHAR(30) NOT NULL, phonenr varchar(20))');
> > 
> > 
> > 
> > Interesting that noone found it before me !
> > 
> > 
> > K
> > 
> 
> It's a flatfile database, not relational, and only uses a small subset 
> of the SQL language.  It also has never had a release version - beta is 
> as far as it ever got.  And it has been abandoned for over 5 years.
> 
> Not what I would call useful.
> 
> -- 
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================

I hoped it could do at least joins, but if it can't do even that, then i believe it's crap....

Kristjan Robam

[toc] | [prev] | [next] | [standalone]


#18243

FromArno Welzel <usenet@arnowelzel.de>
Date2020-03-14 13:21 +0100
Message-ID<hd40htFc5o5U1@mid.individual.net>
In reply to#18236
kristjanise129@gmail.com:

[...]
> http : // gladius . sourceforge . net / install . php

Why don't you just post the correct URL?

<http://gladius.sourceforge.net>

And there is a Github repository as well, but with no development as well:

<https://github.com/kananlanginhooper/Gladius-DB>

> Seems like just what I needed. 
> 
> Size is 166KB unpacked.
> 
> First steps:
> 
>   include 'gladius.php';
>   
>   $G = new Gladius();
>   
>   $G->SetDBRoot('path/to/database_directories') or die;
>   
>   $G->SelectDB('db_directory_or_path_to_db');
>   
>   $G->Query('CREATE TABLE mytable ( id int auto_increment NOT NULL PRIMARY_KEY, name VARCHAR(30) NOT NULL, phonenr varchar(20))');
> 
> 
> 
> Interesting that noone found it before me !

Well - first of all - this project is five(!) years old and was
developed for PHP 4/5. You should not use such things for a production
system.

Gladius may be interesting to learn more about the details how databases
and ADODb work, but for production you should use a real database. And
yes, having the required PHP extensions for database access is a *must*
for any hosting platform. If your hoster does not have this, find
another one.

-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#18244

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-14 09:26 -0700
Message-ID<51893120-aec2-4c51-8cce-5819cc8aa009@googlegroups.com>
In reply to#18243
laupäev, 14. märts 2020 14:21.23 UTC+2 kirjutas Arno Welzel:
> kristjanise129@gmail.com:
> 
> [...]
> > http : // gladius . sourceforge . net / install . php
> 
> Why don't you just post the correct URL?
> 
Sorry.

> <http://gladius.sourceforge.net>
> 
> And there is a Github repository as well, but with no development as well:
> 
> <https://github.com/kananlanginhooper/Gladius-DB>

There seems to be the same version as on <https://sourceforge.net/projects/gladius/files/>

So they don't work, because the one I tried didn't work.

Kristjan

> 
> > Seems like just what I needed. 
> > 
> > Size is 166KB unpacked.
> > 
> > First steps:
> > 
> >   include 'gladius.php';
> >   
> >   $G = new Gladius();
> >   
> >   $G->SetDBRoot('path/to/database_directories') or die;
> >   
> >   $G->SelectDB('db_directory_or_path_to_db');
> >   
> >   $G->Query('CREATE TABLE mytable ( id int auto_increment NOT NULL PRIMARY_KEY, name VARCHAR(30) NOT NULL, phonenr varchar(20))');
> > 
> > 
> > 
> > Interesting that noone found it before me !
> 
> Well - first of all - this project is five(!) years old and was
> developed for PHP 4/5. You should not use such things for a production
> system.
> 
> Gladius may be interesting to learn more about the details how databases
> and ADODb work, but for production you should use a real database. And
> yes, having the required PHP extensions for database access is a *must*
> for any hosting platform. If your hoster does not have this, find
> another one.
> 
> -- 
> Arno Welzel
> https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#18246

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-19 11:43 -0700
Message-ID<3ad86d6b-c9ac-4353-a4e0-44a00b4df1e6@googlegroups.com>
In reply to#18116
People, I have already started to develop this database ("easyphpdb")
Code, if anyone is interested - to get the idea:

<?php
public class Myobj {
   public $a;
   public $a2;
   
   public function getNameOfClass()
   {
      return static::class;
   }
}

public class Easyphpdb {
    function saveobject($obj, $name) {
        if (file_exists($name)) {
            return false;
        }
        $b=serialize($obj);
        $fh = fopen($name, "a");
        fwrite($fh, $b);
        fclose($fh);
        return true;
    }
    function loadobject($name) {
        if (!file_exists($name)) {
            return false;
        }
        $a=file($name);
        $b=unserialize($a);
        return $b;
    }
    
    function query($query, $objects) {
        $ovars=array();
        
        for($i=0; $i<count($objects); $i++) {
            $ovars[]=array_keys(get_object_vars($objects[$i]));       
        }
        $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]->getNameOfClass()."$/",$query)) {
                    $obj1=loadobject($objects[$i]);
                    return array_column($obj1, $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]->getNameOfClass()." join ".$objects[$i]->getNameOfClass()."
                        on ".$objects[$i]->getNameOfClass().".".$ovars[$j]."="
                        .$objects[$k]->getNameOfClass().".".$ovars[$l]."$/",$query)) {
                                  
                            $obj1=loadobject($objects[$i]);
                            $obj2=loadobject($objects[$l]);
                            $outp=array();
                            
                            for($ii=0; $ii<count($objects[$i])) {
                                for($ii1=0; $ii1<count($ovars[$i]; $ii1++))
                                {            
                                   for($ii2=0; $ii2<count($objects[$l])) {
                                       for($ii3=0; $ii3<count($ovars[$i]; $ii3++))
                                       {
                                           if($objects[$i]$ovars[$i][$ii1]==$objects[$l]$ovars[$i][$ii3]) {
                                                  $obj_merged = (object) array_merge((array) $objects[$i]->getNameOfClass(),
                                                  (array) $objects[$l]->getNameOfClass()); 
                                                  $outp[]=$obj_merged;
                                           }                                              
                                       }   
                                      
                                   }
                                
                                }
                            }
                            return $outp;
                        }   
                        $mches=true;
                        break;
                    }
                }
            }
        }


        return $mches;        
    }

}


?>

[toc] | [prev] | [next] | [standalone]


#18247

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-19 13:16 -0700
Message-ID<b5e36966-2555-49fb-979e-4a19c4fa9ec8@googlegroups.com>
In reply to#18116
A little bit fixed and more explained:

<?php
public class Myobj {
   public $a;
   public $a2;
   
   public function getNameOfClass()
   {
      return static::class;
   }
}

public class Myobj2 {
   public $a2;
   public $a3;
   
   public function getNameOfClass()
   {
      return static::class;
   }
}

public 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) {
		  $dbtables[] = unserialize($file);
		}
		$this->setvalue($dbtables);
    }
    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], $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[$i][0]->getNameOfClass()."
                        on (".$objects[$i][0]->getNameOfClass().".".$ovars[$j]."="
                        .$objects[$k][0]->getNameOfClass().".".$ovars[$l].");$/",$query)) {
                                  
                            $outp=array();
                            
                            for($ii=0; $ii<count($objects[$i])) {
                                for($ii1=0; $ii1<count($ovars[$j]; $ii1++))
                                {            
                                   for($ii2=0; $ii2<count($objects[$k])) {
                                       for($ii3=0; $ii3<count($ovars[$l]; $ii3++))
                                       {
                                           if($objects[$i]->$ovars[$j][$ii1]==$objects[$k]->$ovars[$l][$ii3]) {
                                                  $obj_merged = (object) array_merge((array) $objects[$i]->getNameOfClass(),
                                                  (array) $objects[$l]->getNameOfClass()); 
                                                  $outp[]=$obj_merged;
                                           }                                              
                                       }   
                                      
                                   }
                                
                                }
                            }
                            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->saveobject($aone, "Myobj");
$mydb->saveobject($atwo, "Myobj2");

print_r($mydb->query("select * from Myobj;"));
print_r($mydb->query("select * from Myobj2;"));

print_r($mydb->query("select * from Myobj join Myobj2 on (Myobj.a2=Myobj2.a2);"));



?>

[toc] | [prev] | [next] | [standalone]


#18249

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-20 02:31 -0700
Message-ID<bbbfee5c-b333-4ead-993c-5987c551f963@googlegroups.com>
In reply to#18116
I made now a working version.
You can select from tables and join tables.

<?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 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);"));



?>

[toc] | [prev] | [next] | [standalone]


#18250

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-20 05:13 -0700
Message-ID<32d5f2ce-8faa-4580-92e8-da3d0141987a@googlegroups.com>
In reply to#18116
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);"));



?>

[toc] | [prev] | [next] | [standalone]


#18251

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-20 08:09 -0700
Message-ID<4c75a5bd-3d42-4ad4-aa0a-b84762d405e9@googlegroups.com>
In reply to#18116
Meanwhile I have tested and taken off the comments.

Code(Easyphpdb.php):

<?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) {	
        if (file_exists($otabname.".edb")) {
            unlink($otabname.".edb");
        }
        $this->loadobjecttables();
    }
	
    function insertobject($obj) {
		$this->loadobjecttables();
		$oclass=$obj->getNameOfClass();
                echo $oclass;
		$tabls=$this->getvalue();
		$oarridx=-1;
        for($i=0; $i<count($tabls); $i++) {
			if($tabls[$i][0]->getNameOfClass()==$oclass) {
				   $oarridx=$i;
			}
		}
		if($oarridx==-1) 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(); 
          
       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;
                            $mches=true;
                            return $outp;
                            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");

$a1=new Myobj();
$a1->a="333335";
$a1->a2="444445";

//$mydb->insertobject($a1);
//$mydb->deleteotable("Myobj");

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);"));



?>

[toc] | [prev] | [next] | [standalone]


#18252 — Includable simple object based relational php database, that saves data to files and uses only 1 file (the database system php file)

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-21 11:45 -0700
SubjectIncludable simple object based relational php database, that saves data to files and uses only 1 file (the database system php file)
Message-ID<941d4ee8-b899-4f39-953b-5dc72ffb7981@googlegroups.com>
In reply to#18116
Made topic maybe more understandable and updated php file.

Kristjan Robam
Tel. 372 6861327
E-mail: robam man 20 20 @ hot mail . com 

includablesimpleobjectbasedrelationalphpdb.php : 

<?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) {	
        if (file_exists($otabname.".edb")) {
            unlink($otabname.".edb");
        }
        $this->loadobjecttables();
    }
	
    function insertobject($obj) {
		$this->loadobjecttables();
		$oclass=$obj->getNameOfClass();
                echo $oclass;
		$tabls=$this->getvalue();
		$oarridx=-1;
        for($i=0; $i<count($tabls); $i++) {
			if($tabls[$i][0]->getNameOfClass()==$oclass) {
				   $oarridx=$i;
			}
		}
		if($oarridx==-1) 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(); 
          
       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]); 
                            $outp[]=$oobj;
                            $mches=true;
                            return $outp;
                            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");

$a1=new Myobj();
$a1->a="333335";
$a1->a2="444445";

//$mydb->insertobject($a1);
//$mydb->deleteotable("Myobj");

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);"));



?>

[toc] | [prev] | [next] | [standalone]


#18253

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-21 23:29 -0700
Message-ID<3dbf3bbc-2110-4089-9b32-a3a27868348b@googlegroups.com>
In reply to#18116
Change function name.

includablesimpleobjectbasedrelationalphpdb.php:

<?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) {	
        if (file_exists($otabname.".edb")) {
            unlink($otabname.".edb");
        }
        $this->loadobjecttables();
    }
	
    function insertobject($obj) {
		$this->loadobjecttables();
		$oclass=$obj->getNameOfClass();
                echo $oclass;
		$tabls=$this->getvalue();
		$oarridx=-1;
        for($i=0; $i<count($tabls); $i++) {
			if($tabls[$i][0]->getNameOfClass()==$oclass) {
				   $oarridx=$i;
			}
		}
		if($oarridx==-1) 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 objectClassestoarray($objectA, 
                        $objectB) {      
       $new_object = array(); 
          
       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->objectClassestoarray($objects[$i][0], $objects[$k][0]); 
                            $outp[]=$oobj;
                            $mches=true;
                            return $outp;
                            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");

$a1=new Myobj();
$a1->a="333335";
$a1->a2="444445";

//$mydb->insertobject($a1);
//$mydb->deleteotable("Myobj");

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);"));



?>

[toc] | [prev] | [next] | [standalone]


#18254 — Simple object based php database system, that saves data to files and needs only 1 php file(the system php file)

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-24 09:06 -0700
SubjectSimple object based php database system, that saves data to files and needs only 1 php file(the system php file)
Message-ID<d975bb97-9bc6-49a6-8d23-d940808c958c@googlegroups.com>
In reply to#18253
Took off one echo.

Code:

<?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);
        chmod($name.".edb", 0700);
        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) {	
        if (file_exists($otabname.".edb")) {
            unlink($otabname.".edb");
        }
        $this->loadobjecttables();
    }
	
    function insertobject($obj) {
		$this->loadobjecttables();
		$oclass=$obj->getNameOfClass();
		$tabls=$this->getvalue();
		$oarridx=-1;
        for($i=0; $i<count($tabls); $i++) {
			if($tabls[$i][0]->getNameOfClass()==$oclass) {
				   $oarridx=$i;
			}
		}
		if($oarridx==-1) 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);
        chmod($tabls[$oarridx][0]->getNameOfClass().".edb", 0700);
	}
    function objectClassestoarray($objectA, 
                        $objectB) {      
       $new_object = array(); 
          
       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->objectClassestoarray($objects[$i][0], $objects[$k][0]); 
                            $outp[]=$oobj;
                            $mches=true;
                            return $outp;
                            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");

$a1=new Myobj();
$a1->a="333335";
$a1->a2="444445";

$mydb->insertobject($a1);
*/
//$mydb->deleteotable("Myobj");

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);"));



?>

[toc] | [prev] | [next] | [standalone]


#18255

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-24 22:46 -0700
Message-ID<54f1ae6c-ba51-49f6-bf35-f4437606c5a8@googlegroups.com>
In reply to#18116
Fixing.

Code: 

<?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);
        chmod($name.".edb", 0700);
        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) {	
        if (file_exists($otabname.".edb")) {
            unlink($otabname.".edb");
        }
        $this->loadobjecttables();
    }
	
    function insertobject($obj) {
		$this->loadobjecttables();
		$oclass=$obj->getNameOfClass();
		$tabls=$this->getvalue();
		$oarridx=-1;
        for($i=0; $i<count($tabls); $i++) {
			if($tabls[$i][0]->getNameOfClass()==$oclass) {
				   $oarridx=$i;
			}
		}
		if($oarridx==-1) 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);
        chmod($tabls[$oarridx][0]->getNameOfClass().".edb", 0700);
	}
    function objectClassestoarray($objectA, 
                        $objectB) {      
       $new_object = array(); 
          
       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;
                }   
            }
        }
        
        $outp=array();

        for($i=0; $i<count($objects); $i++) {
            for($j=0; $j<count($ovars[$i]); $j++) {
                for($k=0; $k<count($objects); $k++) {
                    for($l=0; $l<count($ovars[$k]); $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)) {
                            for($ii=0; $ii<count($objects[$i]); $ii++) {
                                    for($ii2=0; $ii2<count($objects[$k]); $ii2++) {
                                          if($objects[$i][$ii]->{$ovars[$i][$j]}==$objects[$k][$ii2]->{$ovars[$k][$l]}) {                                             
                                             $oobj = $this->objectClassestoarray($objects[$i][$ii], $objects[$k][$ii2]); 
                                             $outp[]=$oobj;
                                          }
                                    }
                            }
                        } 
                    }
                }
            }
        }
        if(count($outp)>0) {
           return $outp;
        }


        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;

$a1=new Myobj2();
$a1->a2="11111";
$a1->a3="67888";
$atwo[]=$a1;


$mydb=new Easyphpdb();

/*
$mydb->saveobjecttable($aone, "Myobj");
$mydb->saveobjecttable($atwo, "Myobj2");
*/
/*
$a1=new Myobj();
$a1->a="333335";
$a1->a2="444445";

$a1=new Myobj2();
$a1->a2="44444";
$a1->a3="67800";

//$mydb->insertobject($a1);
//$mydb->deleteotable("Myobj");

var_dump($mydb->query("select a from Myobj;"));
var_dump($mydb->query("select a2 from Myobj2;"));
*/
var_dump($mydb->query("select * from Myobj join Myobj2 on (Myobj.a2=Myobj2.a2);"));
var_dump($mydb->query("select * from Myobj join Myobj2 on (Myobj.a=Myobj2.a2);"));



?>

[toc] | [prev] | [next] | [standalone]


#18256

FromKristjan Robam <robamman2020@hotmail.com>
Date2020-03-26 01:16 -0700
Message-ID<54659ffc-04fd-428b-89e8-bba6ea659e18@googlegroups.com>
In reply to#18255
Updated system.

<?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);
        chmod($name.".edb", 0700);
        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) {	
        if (file_exists($otabname.".edb")) {
            unlink($otabname.".edb");
        }
        $this->loadobjecttables();
    }
	
    function insertobject($obj) {
		$this->loadobjecttables();
		$oclass=$obj->getNameOfClass();
		$tabls=$this->getvalue();
		$oarridx=-1;
        for($i=0; $i<count($tabls); $i++) {
			if($tabls[$i][0]->getNameOfClass()==$oclass) {
				   $oarridx=$i;
			}
		}
		if($oarridx==-1) 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);
        chmod($tabls[$oarridx][0]->getNameOfClass().".edb", 0700);
	}
    function objectClassestoarray($objectA, 
                        $objectB) {      
       $new_object = array(); 
          
       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;
		$exitf=false;
		
        for($i=0; $i<count($objects); $i++) {
			if($exitf) break;
            for($j=0; $j<count($ovars); $j++) {
				if($exitf) break;
                if(preg_match("/^select \* from ".$objects[$i][0]->getNameOfClass().";$/",$query)) {
                    $objectsList = [];
					foreach ($objects[$i] as $obj) {        
						$objectsList[] = (array)$obj;
					}
					return $objectsList;
                    $mches=true;
					$exitf=true;
                }   
            }
        }
		
        for($i=0; $i<count($objects); $i++) {
			if($exitf) break;
            for($j=0; $j<count($ovars); $j++) {
				if($exitf) break;
                if(preg_match("/^select ".$ovars[$i][$j]." from ".$objects[$i][0]->getNameOfClass().";$/",$query)) {
                    return array_column($objects[$i], $ovars[$i][$j]);
                    $mches=true;
					$exitf=true;
                }   
            }
        }
        
        $outp=array();
        for($i=0; $i<count($objects); $i++) {
			if($exitf) break;			
            for($j=0; $j<count($ovars[$i]); $j++) {
				if($exitf) break;
				for($k=0; $k<count($objects); $k++) {
					if($exitf) break;
                    for($l=0; $l<count($ovars[$k]); $l++) {
						if($exitf) break;
                        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)) {
                            for($ii=0; $ii<count($objects[$i]); $ii++) {
                                    for($ii2=0; $ii2<count($objects[$k]); $ii2++) {
                                          if($objects[$i][$ii]->{$ovars[$i][$j]}==$objects[$k][$ii2]->{$ovars[$k][$l]}) {                                             
                                             $oobj = $this->objectClassestoarray($objects[$i][$ii], $objects[$k][$ii2]); 
                                             $outp[]=$oobj;
                                          }
                                    }
                            }
						$exitf=true;
                        } 
                    }
                }
            }
        }
        
        for($k=0; $k<count($objects); $k++) {
            if($exitf) break;
            for($l=0; $l<count($ovars[$k]); $l++) {
                if($exitf) break;
                if(preg_match("/^select \* from ".$objects[$k][0]->getNameOfClass()." where ".$ovars[$k][$l]."\=(.*);$/",$query, $matches)) {
                            for($ii2=0; $ii2<count($objects[$k]); $ii2++) {
                                  if($objects[$k][$ii2]->{$ovars[$k][$l]}==$matches[1]) {   
                                     $oobj = (array)$objects[$k][$ii2]; 
                                     $outp[]=$oobj;
                                  }
                            }
                            $exitf=true;
                } 
            }
        }
        
        if(count($outp)>0) {
           return $outp;
        }


        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;

$a1=new Myobj2();
$a1->a2="11111";
$a1->a3="67888";
$atwo[]=$a1;


$mydb=new Easyphpdb();

/*
$mydb->saveobjecttable($aone, "Myobj");
$mydb->saveobjecttable($atwo, "Myobj2");
*/
/*
$a1=new Myobj();
$a1->a="333335";
$a1->a2="444445";

$a1=new Myobj2();
$a1->a2="44444";
$a1->a3="67800";

//$mydb->insertobject($a1);
//$mydb->deleteotable("Myobj");

var_dump($mydb->query("select a from Myobj;"));
var_dump($mydb->query("select a2 from Myobj2;"));
var_dump($mydb->query("select * from Myobj join Myobj2 on (Myobj.a2=Myobj2.a2);"));
var_dump($mydb->query("select * from Myobj join Myobj2 on (Myobj.a=Myobj2.a2);"));
*/
/*
var_dump($mydb->query("select * from Myobj;"));
var_dump($mydb->query("select * from Myobj2;"));

var_dump($mydb->query("select * from Myobj where a=33333;"));
*/
?>

[toc] | [prev] | [next] | [standalone]


#18257

Fromrobamman2020@hotmail.com
Date2020-03-28 08:21 -0700
Message-ID<7a6ad7cf-fef8-4f5c-a56e-47c56d17c707@googlegroups.com>
In reply to#18256
System contains 2 files: myapplication.php and databasesystem.php.

The codes:

myapplication.php:
<?php

include("databasesystem.php");

/* Testing section beginning */

class Myobj extends Dbobj{
   public $a;
   public $a2;
   public $a22;
}

class Myobj2 extends Dbobj{
   public $a2;
   public $a3;
}

$aone=array();

$a1=new Myobj();
$a1->a="11111";
$a1->a2="22222";
$aone[]=$a1;

$a1=new Myobj();
$a1->a="33333";
$a1->a2="44444";
$a1->a22="44445";

$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;

$a1=new Myobj2();
$a1->a2="11111";
$a1->a3="67888";
$atwo[]=$a1;


$mydb=new Easyphpdb();

$tabls1[]=$aone;
$mydb->setvalue($tabls1);
$mydb->saveobjecttable("Myobj");
//$mydb->saveobjecttable("Myobj2");

/*
$a1=new Myobj();
$a1->a="333335";
$a1->a2="444445";

$a1=new Myobj2();
$a1->a2="44444";
$a1->a3="67800";

$a1=new Myobj();
$a1->a="11111";
$a1->a2="22222";
*/
//$mydb->deleteotable("Myobj");

/*
$mydb->insertobject($a1);
$mydb->deleteotable("Myobj");
var_dump($mydb->query("select a from Myobj;"));
var_dump($mydb->query("select a2 from Myobj2;"));
var_dump($mydb->query("select * from Myobj join Myobj2 on (Myobj.a2=Myobj2.a2);"));
var_dump($mydb->query("select * from Myobj join Myobj2 on (Myobj.a=Myobj2.a2);"));
var_dump($mydb->query("select * from Myobj;"));
var_dump($mydb->query("select * from Myobj2;"));
var_dump($mydb->query("select * from Myobj where a=33333;"));
$mydb->deleteduplicates("Myobj");
var_dump($mydb->query("select * from Myobj;"));
*/
var_dump($mydb->query("select * from Myobj where a=33333 and a2=44444;"));


/* Testing section end */

?>

databasesystem.php:

<?php

class Dbobj {
   public function getNameOfClass()
   {
      return static::class;
   }
}

class Easyphpdb {
	
    private $dbtables;
     
    function setvalue($a) {
       $this->dbtables=$a;
    }
     
    function getvalue() {
       return $this->dbtables;
    }

    function saveobjecttables() {
        $tabls=$this->getvalue();
        for($i=0; $i<count($tabls); $i++) {
              $oc=$tabls[$i][0]->getNameOfClass();
              if (file_exists($oc.".edb")) {
                    unlink($oc.".edb");
              }              
              $b=serialize($tabls[$i]);
              $fh = fopen($oc.".edb", "a");
              fwrite($fh, $b);
              fclose($fh);
              chmod($oc.".edb", 0700);
	}
        return true;
    }

    function saveobjecttable($objcl) {
        $tabls=$this->getvalue();
        $obclindex=-1;
        for($i=0; $i<count($tabls); $i++) {
           if($tabls[$i][0]->getNameOfClass()==$objcl) {
              $obclindex=$i;
              break;
           }
        }
        if (file_exists($objcl.".edb")) {
           unlink($objcl.".edb");
        }
        $b=serialize($tabls[$obclindex]);
        $fh = fopen($objcl.".edb", "a");
        fwrite($fh, $b);
        fclose($fh);
        chmod($objcl.".edb", 0700);
        return true;
    }


    function makearrayunique($array){
        $duplicate_keys = array();
        $tmp = array();
        
        foreach ($array as $key => $val){
           if (is_object($val))
            $val = (array)$val;
        
           if (!in_array($val, $tmp))
            $tmp[] = $val;
            else $duplicate_keys[] = $key;
        }
        
        foreach ($duplicate_keys as $key)
          unset($array[$key]);
         return $array;
    }

    function deleteduplicates() {
        $ob=$this->getvalue();
        for($i=0; $i<count($ob); $i++) {
           $o12=$this->makearrayunique($ob[$i]);
           $ob[$i]=$o12;
        }
        $this->setvalue($ob);
        $this->saveobjecttables();
        return 1;
    }

    function deleteduplicate($objcl) {
        $ob=$this->getvalue();
        $obclindex=-1;
        for($i=0; $i<count($ob); $i++) {
           if($ob[$i][0]->getNameOfClass()==$objcl) {
              $obclindex=$i;
              break;
           }
        }        
        $o12=$this->makearrayunique($ob[$obclindex]);
        $ob[$obclindex]=$o12;
        $this->setvalue($ob);
        $this->saveobjecttable($objcl);
        return 1;
    }


    function loadobjecttables() {	
		$dbtables = array();
		foreach (glob("*.edb") as $file) {
                $file1 = file_get_contents($file, true);
		  $dbtables[] = unserialize($file1);
		}
		$this->setvalue($dbtables);
    }
    function deleteotable($otabname) {	
        if (file_exists($otabname.".edb")) {
            unlink($otabname.".edb");
        }
        $this->loadobjecttables();
    }
	
    function insertobject($obj) {
        $this->loadobjecttables();
        $oclass=$obj->getNameOfClass();
        $tabls=$this->getvalue();
        $oarridx=-1;
        for($i=0; $i<count($tabls); $i++) {
			if($tabls[$i][0]->getNameOfClass()==$oclass) {
				   $oarridx=$i;
			}
		}
		if($oarridx==-1) 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);
        chmod($tabls[$oarridx][0]->getNameOfClass().".edb", 0700);
    }
    function objectClassestoarray($objectA, 
                        $objectB) {      
       $new_object = array(); 
          
       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;
		$exitf=false;
		
        for($i=0; $i<count($objects); $i++) {
			if($exitf) break;
            for($j=0; $j<count($ovars); $j++) {
				if($exitf) break;
                if(preg_match("/^select \* from ".$objects[$i][0]->getNameOfClass().";$/",$query)) {
                    $objectsList = [];
					foreach ($objects[$i] as $obj) {        
						$objectsList[] = (array)$obj;
					}
					return $objectsList;
                    $mches=true;
					$exitf=true;
                }   
            }
        }
		
        for($i=0; $i<count($objects); $i++) {
			if($exitf) break;
            for($j=0; $j<count($ovars); $j++) {
				if($exitf) break;
                if(preg_match("/^select ".$ovars[$i][$j]." from ".$objects[$i][0]->getNameOfClass().";$/",$query)) {
                    return array_column($objects[$i], $ovars[$i][$j]);
                    $mches=true;
					$exitf=true;
                }   
            }
        }
        
        $outp=array();
        for($i=0; $i<count($objects); $i++) {
			if($exitf) break;			
            for($j=0; $j<count($ovars[$i]); $j++) {
				if($exitf) break;
				for($k=0; $k<count($objects); $k++) {
					if($exitf) break;
                    for($l=0; $l<count($ovars[$k]); $l++) {
						if($exitf) break;
                        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)) {
                            for($ii=0; $ii<count($objects[$i]); $ii++) {
                                    for($ii2=0; $ii2<count($objects[$k]); $ii2++) {
                                          if($objects[$i][$ii]->{$ovars[$i][$j]}==$objects[$k][$ii2]->{$ovars[$k][$l]}) {                                             
                                             $oobj = $this->objectClassestoarray($objects[$i][$ii], $objects[$k][$ii2]); 
                                             $outp[]=$oobj;
                                          }
                                    }
                            }
						$exitf=true;
                        } 
                    }
                }
            }
        }

        for($k=0; $k<count($objects); $k++) {
            if($exitf) break;
            for($l=0; $l<count($ovars[$k]); $l++) {
                if($exitf) break;
				for($l2=0; $l2<count($ovars[$k]); $l2++) {
					if($exitf) break;	
					if(preg_match("/^select \* from ".$objects[$k][0]->getNameOfClass()." where ".$ovars[$k][$l]."\=(.*) and ".$ovars[$k][$l2]."\=(.*);$/",$query, $matches)) {
								for($ii2=0; $ii2<count($objects[$k]); $ii2++) {
									  if($objects[$k][$ii2]->{$ovars[$k][$l]}==$matches[1]&&$objects[$k][$ii2]->{$ovars[$k][$l2]}==$matches[2]) {   
										 $oobj = (array)$objects[$k][$ii2]; 
										 $outp[]=$oobj;
									  }
								}
								$exitf=true;
					} 
				}
            }
        }

        
        for($k=0; $k<count($objects); $k++) {
            if($exitf) break;
            for($l=0; $l<count($ovars[$k]); $l++) {
                if($exitf) break;
                if(preg_match("/^select \* from ".$objects[$k][0]->getNameOfClass()." where ".$ovars[$k][$l]."\=(.*);$/",$query, $matches)) {
                            for($ii2=0; $ii2<count($objects[$k]); $ii2++) {
                                  if($objects[$k][$ii2]->{$ovars[$k][$l]}==$matches[1]) {   
                                     $oobj = (array)$objects[$k][$ii2]; 
                                     $outp[]=$oobj;
                                  }
                            }
                            $exitf=true;
                } 
            }
        }
        
        if(count($outp)>0) {
           return $outp;
        }


        return $mches;        
    }

}

?>


With best wishes,
Kristjan Robam
Tel. : 372 6861327
E-mail: rob am man 20 20 @ hot mail . com
(Please remove spaces..)

[toc] | [prev] | [next] | [standalone]


#18258

FromLuuk <luuk34@gmail.com>
Date2020-03-28 17:39 +0100
Message-ID<r5nujn$405$1@dont-email.me>
In reply to#18257
On 28-3-2020 16:21, robamman2020@hotmail.com wrote:
> System contains 2 files: myapplication.php and databasesystem.php.
> 

Because this is a lot of work, i mean building 'relational database 
programmed in PHP', can you please give a montly update, and not an 
hourly update ?

please?

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.php


csiph-web