Jump to content

COMPLEX SUBJECT PHP


bigtekno

Recommended Posts

Hello world,

 

i want to write a handler for relational database. This handler will load a database and provide an opportunity for the user to perform read operations, additions and deletions (see list of commands). The user can then enter a number of commands that will be interpreted by the manager.

The file format of the database is free. It has you find the format easier to manage.

 

Program Synopsis:

 

 

$> Php. / db.php

Usage:. / db.php [-i inputfile] [-o outputfile] dbfile

$>

 

    * Mandatory Parameter:

          o 'dbfile': path to the file that contains the database on which to work.

    * Options:

          o-i 'filename': specifies standard input program. If this option is not enabled, standard input program is the system (stdin).

          o-o 'filename': specifies the standard output of the program. If this option is not enabled, standard output of the program is that the system (stdout).

 

 

Once the program starts, it waits on its standard input commands that execute if they sound good. The program ends when it encounters the QUIT command or if the input stream reaches EOF.

Orders:

 

All orders are delineated by a semicolon ';'. An order can be multiple lines. If a syntax error is detected, the program displays the message 'syntax error' and continues to await further orders.

QUIT

 

Exits the program.

Synopsis:

 

QUIT;

 

CREATE TABLE

 

CREATE TABLE creates a table in the database.

Synopsis:

 

CREATE TABLE table_name

(

name_col_1 type [OPTIONS]

name_col_2 type [OPTIONS]

...

);

 

    * 'Table_name': table name to create.

    * 'Nom_col_1': column name to create.

    * 'Type': data type of column.

      Possible types:

          o integer

          o float

          o bool

          o string

    * [Options]: Optional.

          o primary_key: defines the primary key of the table. (It can not have one)

          o not_null: Defines a field as being necessarily different from NULL

 

The name, type and different options are separated by one or more tabs.

 

In our database, a table should always have a single primary key.

 

Example:

 

CREATE TABLE customers

(

id integer primary_key,

not_null string name,

Phnom string,

age integer

);

-> Table 'customers' created.

 

The program should display a message informing the user if the instruction went well.

If the table already exists, the command will display an error.

 

 

This is my code but it is not work, i am a beginner . it's URGENT Thank you.

 

 

#!/usr/bin/php

<?php

function GetNextLine()

{

  $line = rtrim(fgets(STDIN));

  if (feof(STDIN))

    return (false);

  return ($line);

}

 

 

 

function write()

{

  $i=0;

  while ($a != "QUIT;")

    {

    $a=GetNextLine();

    $i++;

    }

}

write();

?>

Link to comment
https://forums.phpfreaks.com/topic/181848-complex-subject-php/
Share on other sites

My code is :

#!/usr/bin/php
<?php

function GetNextLine()
{
  $line = rtrim(fgets(STDIN));
  if (feof(STDIN)) 
    return (false);
  return ($line);
}

$arg = $_SERVER['argv'][1];
if ($arg== NULL)
{
echo "Usage: ./bdphp.php [-i inputfile] [-o outputfile] dbfile";
echo "\n";
}

function FunWrite()
{
  $i=0;
  while($a != "QUIT;")
  {
     echo "\n";
     $a=GetNextLine();
     $i++;
     echo "syntax error";
   }
}
FunWrite();
?>

 

when i execute it , even if $a != "QUIT; , its return "syntax error".

bigtekno:~$ php ./db.php
Usage: ./bdphp.php [-i inputfile] [-o outputfile] dbfile

test
syntax error
QUIT;
syntax errorbigtekno:~$ 

 

and i dont`t have idea on how to insert CREATE TABLE, DESC and INSERT ???

Link to comment
https://forums.phpfreaks.com/topic/181848-complex-subject-php/#findComment-959140
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.