[php] Script testen

Pagina: 1
Acties:
  • 52 views sinds 30-01-2008

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Hallo,

Ik ben hier om m'n stage plek en ik heb niet de beschikking over een php server... kan iemand mijn scripten testen zodat ik weer verder kan? Het is een class die gebruik maakt van een flat file en het idee heeft van een DBMS heel heeeeel simpel... dit is trouwens de eerste keer dat ik OOP programmeer... wil iemand dit doen?
PHP:
1
<?class Flat_DB {    var $error_list; // List with errors    var $current_db_file; // Curent db file    var $fp; // File open 0/1    var $records_arr = array(); // All lines in the file as a array    var $record = array(); // Last opend record    var $records = array(); // Current records    var $result = array(); // Result of a select    // Update a record, remember that you include all the fields, alsow the empty. The last three are    // the value to compare to, the field number and does it have to be a compair or a like (1,2) If you want to update all the fields in the    // database you stil have to use the last fields but ust fill in nothing    function Flat_Update_Record() {        if(!Flat_DB_Open()) {            return false;        } else {                    $record_int = array();            $numargs = func_num_args();            if($numargs > 3) {                $arg_list = func_get_args();                for($i=0;$i<=sizeof($arg_list)-3;$i++) {                    $record_int[] = $arg_list[$i];                }                $records_int = Flat_Get_Records();                for($i=0;$i<=sizeof($records_int);$i++) {                    if($arg_list[$num_args] == 1) {                        if($record_int[$i][$arg_list[$num_args-1]] == $arg_list[$num_args-2]) {                            $this->records[$i] = $record_int[$i];                        }                    } elseif($arg_list[$num_args] == 2) {                        if(ereg($arg_list[$num_args-2],$record_int[$i][$arg_list[$num_args-1]])) {                            $this->records[$i] = $record_int[$i];                        }                    }                }                for($i=0;$i<=sizeof($this->records);$i++) {                    for($i_int=0;$i_int<=sizeof($this->records[$i])-1;$i_int++) {                        fputs($this->fp,"\""$this->records[$i][$i_int]."\"    ");                    }                    fputs($this->fp,"\""$this->records[$i][sizeof($this->records[$i])]."\"\n");                }                flock($this->fp,3);            } else {                Flat_Add_Error('You have to give at least 4 arguments (Flat_Update_Record(field,field,etc,value,fieldnumber))');            }        }    }        // Inserts a record, yust give all the fields as an argument like Flat_Inset_Field($field1, $field2, etc, etc)    function Flat_Insert_Record() {        if(!Flat_DB_Open()) {            return false;        } else {                    $numargs = func_num_args();            $arg_list = func_get_args();            for ($i=0;$i<=$numargs;$i++) {                $field = "\"".$arg_list[$i]."\"";                if($i == sizeof($numargs))                    $field .= "\n";                else                    $field .= "    ";                if(!fputs($fp,$field)){                    Flat_Add_Error('Coudn\'t add record');                    return false;                }            }        }    }        // Returns the records who meet with the specified value in a specified field    function Flat_Reverse_Result($resultin = '') {        if(!Flat_DB_Open()) {            return false;        } else {            if(empty($resultin))                $resultin = $this->records;            for($i=0;$i<=sizeof($resultin);$i++)                $this->result[sizeof($resultin)-$i] = $resultin[$i];            return $this->result        }        }        // Returns a array with all the records (Fields seperated by a tab)    function Flat_Get_File_Array() {        if(!Flat_DB_Open()) {            return false;        } else {            while(!feof($this->fp)) {                $this->records_arr[] = fgets($this->fp, 4096);            }            return $this->records_arr;        }    }        // Returns the records who meet with the specified value in a specified field    function Flat_Select_Record($value,$field) {        if(!Flat_DB_Open()) {            return false;        } else {            for($i=0;$i<=sizeof($this->records);$i++) {                $this->records[$i][$field] = $value;                $this->result[] = $this->records[$i];            }            return $this->result        }        }        // Returns the records who are like the specified value in a specified field    function Flat_Search_Record($value,$field,$case = '1') {        if(!Flat_DB_Open()) {            return false;        } else {            for($i=0;$i<=sizeof($this->records);$i++) {                if($case)                    if(ereg($value,$this->records[$i][$field]))                        $this->result[] = $this->records[$i];                elseif(!$case)                    if(eregi($value,$this->records[$i][$field]))                        $this->result[] = $this->records[$i];            }            return $this->result;        }        }    // Puts the records in an two demensional array    function Flat_Get_Records() {        if(!Flat_DB_Open()) {            return false;        } else {            if(sizeof($this->records_arr) <= 0)                Flat_Get_File_Array();            for($i=0;$i<=sizeof($this->records_arr);$i++) {                $int_arr = split("    ",$this-records_arr[$i]);                for($int_i=0;$int_i<=sizeof($int_arr);$int_i) {                    $this->record[$int_i] = substr(substr($int_arr[$int_i],1),-1);                }                $this->records[$i] = $this->record;            }        }    }    // Checks if DB is open    function Flat_DB_Open() {        if(!$this->fp) {            Flat_Add_Error('DB File not opened');            return false;        } else {            return true;        }    }        function Flat_Close_DB($fp){        if(!Flat_DB_Open()) {            return false;        } else {            unset($this->fp);            fclose($fp);        }    }        // Opens a file for reading and writing    function Flat_Open_DB($file) {        if(empty($file)) {            Flat_Add_Error('You didn\'t specify a file');            return false;        } else {            $this->fp = fopen($file,'r+');            if(!$this->fp) {                Flat_Add_Error('Error opening file');                return false;            } else {                $this->current_db_file = $file;                return true;            }        }    }        // Used for adding a error to the error list    function Flat_Add_Error($err) {        if(!empty($err)) {            $this->error_list[] = $err;        }    }    // Returns all errors in a array    function Flat_All_Errors() {        return $this->error_list;    }        // Use this function to show error's    function Flat_Error($no = '') {        if(empty($no)) $no = sizeof($this->error_list);        else $no = sizeof($this->error_list) + $no;        echo $this->error_list[$no];    }}?>

Dit is een voorbeeld voor het gebruik van het script
PHP:
1
<?include("flat_db.php"); // Include the class file$flat = new Flat_DB; // Make a new object$flat->Flat_Open_DB("exampledb.cvs"); // Open the DB file exampledb.cvs$records = $flat->Flat_Get_Records(); // Get the records and put them in a arrayfor($i=0;$i<=sizeof($records);$i++) { // Go with a loop trough the records    echo "Id: $records[$i][0]<br>\n"; // Each field has a number, starting with 0 (zero)    echo "Name: $records[$i][1]<br>\n";    echo "Adress: $records[$i][2]<br>\n";}$flat->Flat_Close_DB(); // You don't have to but it is better Close the DB file?>

Voorbeeld databees bestandje: (Moet met tabs gescheiden zijn)
code:
1
2
"1" "Ate Bontjer"   "De Voorreep 48"
"2" "Piet Paulusma" "Pieterlaan 12"

PS: Ik hier niets in de FAQ gelezen over dit, maar ik weet het niet zeker...

  • Glimi
  • Registratie: Augustus 2000
  • Niet online

Glimi

Designer Drugs

(overleden)

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
ik mag hier niks installeren...

  • MikeN
  • Registratie: April 2001
  • Laatst online: 13-09 17:41
Kun je niet een linkie geven naar een .txt file? Dan kan ik hem wel uittesten, maar dit is niet te doen, aangezien IE de regeleinden niet meeknipt.

Verwijderd

ja of installeer ff php servertje in combi met apache op je eigen systeem :? ik ga toch ook hier niet vragen of iemand mijn java source wil compileren omdat ik geen zin heb compiler te installeren? :D beetje rare vraag vind ik dit :Z

bedoel het niet lullig hoor, maar komop, denk eens na.
Op vrijdag 01 maart 2002 13:27 schreef Monstar.nl het volgende:
ik mag hier niks installeren...
mag je dan wel voor jezelf php-en op je stage?
neem aan als het in belang is van het bedrijf dat jij best iets mag installeren hoor :9

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
ik heb geen toegang tot een ftp server... is er niet ergens iets waar ik temp kan uploaden... van m'n eigen (monstar.nl) ligt de ftp plat...

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Op vrijdag 01 maart 2002 13:29 schreef woeitje het volgende:
ja of installeer ff php servertje in combi met apache op je eigen systeem :? ik ga toch ook hier niet vragen of iemand mijn java source wil compileren omdat ik geen zin heb compiler te installeren? :D beetje rare vraag vind ik dit :Z

bedoel het niet lullig hoor, maar komop, denk eens na.
[..]

mag je dan wel voor jezelf php-en op je stage?
neem aan als het in belang is van het bedrijf dat jij best iets mag installeren hoor :9
Ja, ik mag php'en... maar niets installeren... dit ivm het werken met thin clients

  • MikeN
  • Registratie: April 2001
  • Laatst online: 13-09 17:41
Op vrijdag 01 maart 2002 13:30 schreef Monstar.nl het volgende:
ik heb geen toegang tot een ftp server... is er niet ergens iets waar ik temp kan uploaden... van m'n eigen (monstar.nl) ligt de ftp plat...
Dan moet je ff 3 tellen w8ten, dan regel ik wat voor je...

  • Glimi
  • Registratie: Augustus 2000
  • Niet online

Glimi

Designer Drugs

(overleden)
Gratis PHP hosting provider:
[url="http://gathering.tweakers.net/forum/find/keyword?data%5Bq%5D=php+hosting&data%5Border%5D=relevance#hitstart]http://gathering.tweakers.net/forum/find/keyword?data%5Bq%5D=php+hosting[/url]&data%5Border%5D=relevance#hitstart

http://www.google.nl/search?q=Free+PHP+hosts&hl=nl&lr=

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Op vrijdag 01 maart 2002 13:32 schreef MikeN het volgende:

[..]

Dan moet je ff 3 tellen w8ten, dan regel ik wat voor je...
Zou koel zijn!

  • MikeN
  • Registratie: April 2001
  • Laatst online: 13-09 17:41
Op vrijdag 01 maart 2002 13:32 schreef Monstar.nl het volgende:

[..]

Zou koel zijn!
Kun je bij je mail? Zodat ik je login kan mailen?

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Op vrijdag 01 maart 2002 13:33 schreef MikeN het volgende:

[..]

Kun je bij je mail? Zodat ik je login kan mailen?
Yep, webmail :)

  • MikeN
  • Registratie: April 2001
  • Laatst online: 13-09 17:41
Op vrijdag 01 maart 2002 13:34 schreef Monstar.nl het volgende:

[..]

Yep, webmail :)
Check je mail.

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Op vrijdag 01 maart 2002 13:36 schreef MikeN het volgende:

[..]

Check je mail.
Thank you verry much!

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Na alle standaard parse errors d'r hebben uitgehaald krijg ik een timeout op regel 137... wat is er mis mee?
PHP:
1
<?    // Puts the records in an two demensional array    function Flat_Get_Records() {        if(!$this->Flat_DB_Open()) {            return false;        } else {            $int_arr = array();            if(sizeof($this->records_arr) <= 0)                $this->Flat_Get_File_Array();            for($i=0;$i<=sizeof($this->records_arr);$i++) {                $int_arr = split("    ",$this->records_arr[$i]);                for($int_i=0;$int_i<=sizeof($int_arr);$int_i) {                    $this->record[$int_i] = substr(substr($int_arr[$int_i],1),-1); // Regel 137                }                $this->records[$i] = $this->record;            }        }    }?>

  • MikeN
  • Registratie: April 2001
  • Laatst online: 13-09 17:41
PHP:
1
<?for($int_i=0;$int_i<=sizeof($int_arr);$int_i) {?>

Mist daar niet een ++ ?

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Op vrijdag 01 maart 2002 13:53 schreef MikeN het volgende:
PHP:
1
<?for($int_i=0;$int_i<=sizeof($int_arr);$int_i) {?>

Mist daar niet een ++ ?
|:( Jezus wat ben ik een ukkel...

  • RedHat
  • Registratie: Augustus 2000
  • Laatst online: 21:26
monstar.nl heeft bijna exact het zelfde design als php.net

...

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Behalve de kleur en het logo en de bron is ook heel wat anders... monstar is bijvoorbeeld geschikt voor 640x480... maarrrrrr... er is een nieuw desing op komst zoals ook te lezen op de frontpage...

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Hoe haal ik een break (\n) van een regel af?

ereg_replace("\n","",$line);

werkt niet...

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
iemand?

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Op vrijdag 01 maart 2002 13:36 schreef MikeN het volgende:

[..]

Check je mail.
Ligt je server plat?

  • martinvw
  • Registratie: Februari 2002
  • Laatst online: 13-09 08:16

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
Op vrijdag 01 maart 2002 15:16 schreef M4rt1nvW het volgende:
trim($string);

http://www.php.net/manual/en/function.trim.php
Die haalt ook de tabs weg...

  • Slagroom
  • Registratie: Juni 2001
  • Laatst online: 23-08 10:29
trim($line,"\n");

  • D2k
  • Registratie: Januari 2001
  • Laatst online: 31-08 10:19

D2k

dit is gewoon een "help-me-ff"-topic

Doet iets met Cloud (MS/IBM)

Pagina: 1

Dit topic is gesloten.