Skip to content
Apoorva Singh edited this page Jul 1, 2017 · 11 revisions

Getting started

When you will start using graphDB for the first time you need to setup the tables in your MySQL database for the same. To do that initial work for you, we have created a function called setupTables($conn) which creates all the tables if they don't already exist in the database.

Note that the time zone is set to Asia/Kolkata you can go ahead and change that whenever you want.

This function sets up the required tables in the selected database. A mysqli connection object should be passed to the function with the database already selected. For example,

require "graphDB.php";

$conn = mysqli_connect("localhost","root","pass","MyDB");
$out = setupTables($conn);

if($out=="ok") {
    echo "Tables created successfully.";
}
else {
    echo "Error in creating tables.";
}

Library Reference

Here is the list of all functions present in this library.

setupTables($conn)

This function creates all the tables required for storing graph data.

Parameters

  • $conn - A mysqli connection object with the database already selected.

Returns

  • A string "ok" if the tables were created successfully.
  • In case of an error it returns an array which looks like {"graphdb_entites":"error string", "graphdb_relations":error string", "graphdb_props":"error string"}. For eg. If there an error in creating "graphdb_relations" table then the error string would look like {"graphdb_entites":"","graphdb_realtions":"error string","graphdb_props":""}.

createNewEntity($conn,$name)

Creates a new entity with the given name.

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $name - Name of the entity

Returns

  • A string "ok" if the entity was created successfully.
  • In the case of an error it returns the error string.

setLabelForEntity($conn,$id,$label)

Sets a label for an entity with given id and label parameters.

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $id - ID of the entity for which you want to set the label
  • $label - Label of the entity

Returns

  • A string "ok" if the label for the entity was set successfully.
  • In the case of an error it returns the error string.

setEntityProperty($conn,$id,$key,$value)

Set a key-value property of the entity using its ID.

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $id - ID of the entity for which you want to set the label
  • $key - key name of the entity
  • $value - value of the entity for the given key

Returns

  • A string "ok" if the key-value property of the entity was set successfully.
  • In the case of an error it returns the error string.

setEntityRelationLabel($conn,$e1_id,$e2_id,$label)

The a label on the relationship between two entities.

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $e1_id - ID of the first entity
  • $e2_id- ID of the second entity
  • $label- Name of the realtionship

Returns

  • A string "ok" if the tables were created successfully.
  • In the case of an error it returns the error string.

getIDByName($conn,$name)

Gets the ID of the entity by using the provided name. If multiple entities exists with the same name then it returns an array of IDs.

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $name - Name of the entity.

Returns

  • An array containing the IDs of the entities with that name. Eg. [21,6,34] or if only one id matches it will also return that in an array [63]
  • If nothing is found it returns an empty array i.e. []
  • In case of an error it returns an empty array i.e. []

getEntityLabels($conn,$id)

Gets the entity's label with ID

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $id- ID of the entity whose label you want.

Returns

  • An array containing the labels of the entity. Eg. ["MEDICAL STORE","SHOP"]. If it only contains a single label it will still return it in an array ["SHOP"]
  • If nothing is found it returns an empty array i.e. []
  • In case of an error it returns an empty array i.e. []

getEntityName($conn,$id)

Gets the entity's name with ID

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $id- ID of the entity whose name you want.

Returns

  • A string containing the name of the entity if everything went fine.
  • If nothing is found it returns an empty string
  • In case of an error it returns an empty string

getAllProperties($conn,$id)

Get all the properties of the entity whose ID has been provided.

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $id - ID of the entity whose name you want.

Returns

  • An array containing the key-value properties of that entity if everything was ok. For eg. {"estab":1997, "month_estab":"January","stock":5000}
  • If nothing is found it returns an empty array
  • In case of an error it returns an empty array

getRelationProperty($conn,$e1_id,$e2_id)

Gets the key-value properties of the realtionship between the two entities

Parameters

  • $conn - A mysqli connection object with the database already selected.
  • $e1_id - ID of the first entity.
  • $e2_id - ID of the second entity.

Returns

  • An array containing the key-value properties of the relationship between the given two entities if everything was ok. For eg. {"sells_to":"True", "is Friend":"False"}
  • If nothing is found it returns an empty array
  • In case of an error it returns an empty array