progetto201 API
Functions | Variables
db_connection.php File Reference

DB_CONNECTION: manages database connection and queries. More...

Functions

 dbconn ($dbname)
 Connects to a database and returns errors or connection object. More...
 
 queryToArray ($t_mysqli, $t_query)
 This function executes the query and returns the data. More...
 
 queryToJson ($t_mysqli, $t_query)
 Returns data as JSON. More...
 

Variables

 $db_dbname = "db100_100"
 

Detailed Description

DB_CONNECTION: manages database connection and queries.

This script defines a function to connect to the database and two function that execute queries (one returns data in an array and the other as JSON)

Since
01_01
Author
Stefano Zenaro (https://github.com/mario33881)

Function Documentation

◆ dbconn()

dbconn (   $dbname)

Connects to a database and returns errors or connection object.

This function connects to the database by reading credentials stored inside the 'credentials.ini' file.

Since
01_01
Parameters
string$dbnamedatabase name
Returns
array $conn_res array with errors or connection object

◆ queryToArray()

queryToArray (   $t_mysqli,
  $t_query 
)

This function executes the query and returns the data.

Executes the query, obtains data and stores it in an array, clears memory and returns the array

Since
01_01
Parameters
object$t_mysqliconnection object
string$t_queryquery to execute
Returns
array $query_res array with query data or errors

◆ queryToJson()

queryToJson (   $t_mysqli,
  $t_query 
)

Returns data as JSON.

Uses the queryToArray() to get data as an array and then encodes it into JSON.

Since
01_01
Parameters
object$t_mysqliconnection object
string$t_queryquery to execute
Returns
array $query_res array with query data or errors

Variable Documentation

◆ $db_dbname

$db_dbname = "db100_100"