Menu

Reference

Bring It To  Code

# REFERENCE

Connecting

// Class
new mysql\mop();

Argument: support 3 or 4 arguments.(counting from 0 position)

Argument type: All string.

Argument order: Database address, Database username, Database password, Database name, driver(optional) pdo or mysqli.

Documentation: Connection.

Usage:

//connect using default setting in mopconfig.php
$firstconnection = new mysql\mop($DB_ADDRESS,$DB_USER,$DB_PASS,$DB_NAME);

// OR connect to pdo
$firstconnection = new mysql\mop($DB_ADDRESS,$DB_USER,$DB_PASS,$DB_NAME,'pdo');

//OR connect to mysqli
$firstconnection = new mysql\mop($DB_ADDRESS,$DB_USER,$DB_PASS,$DB_NAME,'mysqli');

Query

//method
->query();

Argument: support 1 argument.

Argument type: string.

Argument order: none.

Support: MYSQLI and PDO connection.

Documentation: Query.

Usage:

//query
$query = "SELECT ....";
$firstconnection->query($query);

// query with parameter
$query = "SELECT .... WHERE name = ? OR ?";
$firstconnection->query($query);

Bind parameter

// Method
->param()

Argument: mysqli or pdo bind param argument.

Argument type: mysqli or pdo bind param type.

Argument order: mysqli or pdo bind param order.

Support: MYSQLI and PDO connection.

Documentation: Bind parameter.

Usage:

//if connection is by mysqli
$name = 'my name';
$name2 = 'second';
$firstconnection->param('ss',$name,$name2)

//if connection is by pdo (named parameter)
$name = 'my name';
$id = 5;
$firstconnection->param(:id,$id);
$firstconnection->param(:name,$name);

//if connection is by pdo (unnamed parameter)
$name = 'my name';
$id = 5;
$firstconnection->param(1,$id);
$firstconnection->param(2,$name);

Run query

// Method
->run()

Argument: none.

Argument type: none.

Argument order: none.

Support: MYSQLI and PDO connection.

Documentation: RUN.

Usage:

//use it after you've use query() or param() method
$firstconnection->run();

Advance Bind parameter

// Method
->run_all()

Argument: support 1 argument.

Argument type: array or object.

Argument order: parameter order.

Support: PDO connection only.

Documentation: Array binding, Object binding

Usage:

//Bind param and run directly without passing through param() method, also support associative array
// Check documentation for more
$arrayname = array('my name','second');
$firstconnection->run_all($arrayname);

// Also support object, check documentation for more.
$objectname = names() //object is reture
$firstconnection->run_all($objectname);

Add new query

// Method
->add_query()

Argument: support 1 argument.

Argument type: string.

Argument order: QUERY.

Support: MYSQLI and PDO connection.

Documentation: Add query.

Usage:

//Add query to your previous query and get result immediately
$query = "SELECT....";
$firstconnection->add_query($query);

Get column

// Method
->get_column()

Argument: support 1 argument.

Argument type: string or integer.

Argument order: COLUMN INDEX.

Support: MYSQLI and PDO connection.

Documentation: Get column.

Usage:

//Get any column either by it's name or index
$name = 'name';
$index = 3;
$firstconnection->get_column($name); //array is return
$firstconnection->get_column($index); //array is return

Reconnect

// Method
->reconnect()

Argument: no argument.

Support: MYSQLI and PDO connection.

Documentation: Reconnect.

Connection will be close and reconnect.

Change database

// Method
->change_db()

Argument: support 1 argument.

Argument type: string.

Argument order: DATABASE NAME.

Support: MYSQLI and PDO connection.

Documentation: change database.

Usage:

$firstconnection->change_db('new database name');

Change host

// Method
->change_host()

Argument: support 1 argument.

Argument type: string.

Argument order: HOST NAME.

Support: MYSQLI and PDO connection.

Documentation: change host.

Usage:

$firstconnection->change_host('new host name');

Change password

// Method
->change_password()

Argument: support 1 argument.

Argument type: string.

Argument order: PASSWORD.

Support: MYSQLI and PDO connection.

Documentation: change password.

Usage:

$firstconnection->change_password('new password');

Change username

// Method
->change_username()

Argument: support 1 argument.

Argument type: string.

Argument order: USERNAME.

Support: MYSQLI and PDO connection.

Documentation: change username.

Usage:

$firstconnection->change_db('new username');

Change all information

// Method
->change_all()

Argument: support 4 argument.

Argument type: string.

Argument order: HOST NAME, USERNAME, PASSWORD, DATABASE NAME.

Support: MYSQLI and PDO connection.

Documentation: change all information.

Usage:

$firstconnection->change_all('new host name', 'new username', 'new password', 'database name');

Multiple query

// Method
->multi_query()

Argument: support 1 argument.

Argument type: string.

Argument order: ALL QUERY.

Support: MYSQLI and PDO connection only.

Documentation: Multi query.

Usage:

//Run multiple query at once
$query = "SELECT...;SELECT...;INSERT...;UPDATE...";
$firstconnection->multi_query($query);

Multiple query - get column

// Method
->multi_get_column()

Argument: support 2 argument.

Argument type: string or integer.

Argument order: QUERY INDEX, COLUMN INDEX.

Support: MYSQLI and PDO connection only.

Documentation: Multiple query Get column.

Usage:

//Get any column either by it's name or index in multi query
$name = 'name';
$index = 3;
$queryIndex = 1; // Query index in multi_query() method
$firstconnection->multi_get_column($queryIndex,$name);
$firstconnection->get_column($queryIndex,$index);

Multiple query - get result as csv

// Method
->multi_csv()

Argument: support 1 argument.

Argument type: integer.

Argument order: QUERY INDEX.

Support: MYSQLI and PDO connection only.

Documentation: multi csv.

Usage:

//Get any result as csv
$queryIndex = 0;
$firstconnection->multi_csv($queryIndex);

Multiple query - get result as csv with header row

// Method
->multi_csv_header()

Argument: support 1 argument.

Argument type: integer.

Argument order: QUERY INDEX.

Support: MYSQLI and PDO connection only.

Documentation: multi csv with header.

Usage:

//Get any result as csv with header row
$queryIndex = 0;
$firstconnection->multi_csv_header($queryIndex);

Multiple query - get result header row

// Method
->multi_header_row()

Argument: support 1 argument.

Argument type: integer.

Argument order: QUERY INDEX.

Support: MYSQLI and PDO connection only.

Documentation: multi header row.

Usage:

//Get any result as csv with header row
$query = "SELECT...;INSERT...;UPDATE...";
$firstconnection->multi_query($query);
$queryIndex = 0;
$firstconnection->multi_header_row($queryIndex);

Multiple query - get last insert Id

// method
->multi_insert_id()

Argument: support 1 argument.

Argument type: integer.

Argument order: QUERY INDEX.

Support: MYSQLI and PDO connection only.

Documentation: Multi insert id.

Usage:

//get last insert id of any insert statement in multi query
$query = "SELECT...;INSERT...;UPDATE...";
$firstconnection->multi_query($query);
$firstconnection->multi_insert_id(1);

Multiple query - get number of affected or selected

// method
->multi_num_of_rows()

Argument: support 1 argument.

Argument type: integer.

Argument order: QUERY INDEX.

Support: MYSQLI and PDO connection only.

Documentation: Multi num of rows.

Usage:

//get number of affected or selected rows
$query = "SELECT...;INSERT...;UPDATE...";
$firstconnection->multi_query($query);
$firstconnection->multi_num_of_rows(0);

Fresults

// Method
->free_results()

Argument: no argument.

Support: MYSQLI and PDO connection.

Documentation: free results.

Usage:

$firstconnection->free_results();

Log warning

// Method
->log_warning()

Argument: support 1 argument.

Argument type: boolean.

Argument order: none.

Support: MYSQLI connection only.

Documentation: log warning.

Usage:

//Change the state of log warning on the run
$firstconnection->log_warning(true);

Close connection

// Method
->close()

Argument: none.

Argument type: none.

Argument order: none.

Support: MYSQLI and PDO connection.

Documentation: close connection.

Usage:

//Close the connection for either mysqli or pdo connection
$firstconnection->close();


Get column as csv

// property
->csv

Type: string.

Support: MYSQLI and PDO connection.

Documentation: csv.

Usage:

//Get any result as csv, null if no result
$firstconnection->csv;

import csv

// method
->import_csv();

Argument: 5.

Support: MYSQLI and PDO connection.

Argument order: IS_STRING, CSV FILE OR STING, TABLE NAME, COLUMN ORDER (optional), HAS HEADER (optional).

Documentation: import csv.

Usage:

//import data using csv
$column_order = array('id', 'name')
$firstconnection->import_csv(false, 'path/to/csv/file', 'table_name', $column_order, false);

import csv settings

->import_csv_settings();

Argument: 3.

Support: MYSQLI and PDO connection.

Argument order: INSERT TYPE, SEPERATOR, ENCLOSURE.

Documentation: import csv settings.

Usage:

// set import csv settings
$firstconnection->import_csv_settings('update', ',', '"');

import csv num of rows

//property
->import_csv_num_of_rows;

Support: MYSQLI and PDO connection.

Documentation: import csv number of rows.

Usage:

// get number of affected row
$firstconnection->import_csv_num_of_rows;

Multiple query - get all result as csv

// property
->multi_csv

Type: array.

Support: MYSQLI connection only.

As from version 2.1.0 ... It now support MYSQLI and PDO connection.

Documentation: Multi csv.

Usage:

//Get the header row of query index
$query = "SELECT...;INSERT...;UPDATE...";
$firstconnection->multi_query($query);
$firstconnection->multi_csv;

Get column as csv with header

// property
->csv_header

Type: string.

Support: MYSQLI and PDO connection.

Documentation: csv header.

Usage:

//Get any result as csv with header, null if no result
$firstconnection->csv_header;

Multiple query - get all result as csv with header

// property
->multi_csv_header

Type: array.

Support: MYSQLI connection only.

As from version 2.1.0 ... It now support MYSQLI and PDO connection.

Documentation: Multi csv header.

Usage:

//Get the header row of query index
$query = "SELECT...;INSERT...;UPDATE...";
$firstconnection->multi_query($query);
$firstconnection->multi_csv_header;

Get all header row

// property
->header_row

Type: array.

Support: MYSQL and PDO connection.

Documentation: header row.

Usage:

//Get any header row result, null if no result
$firstconnection->header_row;

Multiple query - get all result header row

// property
->multi_header_row

Type: array.

Support: MYSQLI connection only.

As from version 2.1.0 ... It now support MYSQLI and PDO connection.

Documentation: Multi header row.

Usage:

//Get the header row of query index
$query = "SELECT...;INSERT...;UPDATE...";
$firstconnection->multi_query($query);
$firstconnection->multi_header_row;

Get error

// property
->error

Type: boolean.

Support: MYSQLI and PDO connection.

Documentation: error.

Usage:

//check if there is any error 
$firstconnection->error;

Get error message

// property
->error_message

Type: string.

Support: MYSQLI and PDO connection.

Documentation: error message.

Usage:

//It return an error message if there is any 
$firstconnection->error_message;

Get warning

// property
->warning

Type: boolean.

Support: MYSQLI connection only and is NOT supported by multi query.

Documentation: warning.

Usage:

//check if there is any warning
$firstconnection->warning;

Get warning number

// property
->num_of_warnings

Type: Integer.

Support: MYSQLI connection only and NOT supported by multi query.

Documentation: warning error number.

Usage:

//Get number of warnings that occur
$firstconnection->num_of_warnings;

Get warning error number

// property
->warning_errno

Type: array.

Support: MYSQLI connection only and NOT supported by multi query.

Documentation: warning error number.

Usage:

//Get warning error number if there is any
//loop through to get all number
$firstconnection->warning_errno;

Get warning message

// property
->warning_message

Type: array.

Support: MYSQLI connection only and NOT supported by multi query.

Documentation: warning message.

Usage:

//Get warning message of any query that has warning
//loop through to get all message
$firstconnection->warning_message;

Get warning sql state

// property
->warning_sqlstate

Type: array.

Support: MYSQLI connection only and NOT supported by multi query.

Documentation: warning sqlstate.

Usage:

//Get warning sql state of any query that has warning
//loop through to get all state
$firstconnection->warning_sqlstate;

Get number of rows

// property
->num_of_rows

Type: Integer.

Support: MYSQLI and PDO connection.

Documentation: Number of rows.

Usage:

//Get number of affected of selected rows
$firstconnection->num_of_rows;

Get last insert Id

// property
->insert_id

Type: Integer.

Support: MYSQLI and PDO connection.

Documentation: Last Insert id.

Usage:

//check if there is any warning 
$firstconnection->insert_id;

Perform your query

// property
->connect

Type: object.

Support: MYSQLI and PDO connection.

Documentation: connect.

Usage:

//Run your query your way using the connect property 
$newconnect->connect;

Procedure inside multiple query

Documentation: procedure in multi query.



Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.