Connecting & Using Other Databases
Required Namespace
  • Ness
    • Autopulse
      • dbConnect
  • Ness
    • Autopulse
      • dbCommand

You can include this library to your code file by typing the below code;

use Ness\Autopulse\dbConnect

use Ness\Autopulse\dbCommand


dbConnect Class #top

Create a Connection

You can create your connection in construct when you define your database variable.

                                    $connection = new dbConnect($host, $user, $pass, $db, $options);
                                
Create a new connection
Return Object
Parameters $host String; Connection Host
$user String; Username of connection
$pass String; Password for connection
$db String; Database name
$options Array Optional;PHP PDO Options






Connection Source

This function is used to return an active database connection.

                                    $connection->Source();
                                
Get an active connection for using with dbConnect class.
Return PDO Connection
Parameters None



Check Connection

Check if connection is available

                                    $connection->isConnected();
                                
Check for active connection
Return Boolean
Parameters None






Error List

Show last connection errors.

                                    $connection->lastError();
                                
Check for last connection error
Return String
Parameters None






Reconnect to Database

Reconnect to active database.

                                    $connection->Connection($host, $user, $pass, $db, $options);
                                
Create a new connection
Return Object
Parameters $host String; Connection Host
$user String; Username of connection
$pass String; Password for connection
$db String; Database name
$options Array Optional;PHP PDO Options






Close an Active COnnection

Close connection to active database.

                                        $connection->Close();
                                    
Close a connection
Return Boolean
Parameters None









dbCommand Class #top

Create Command
$cmd = new dbCommand(String $command, dbConnect | MySqlConnect  $source);
You need create an instance of dbCommand library for your commands. You can define your command when creating a dbCommand instance
Return Command Object
Parameters $command String; Command to run
$source Connection Source; MySqlConnect or dbConnect connection source; ex: $connection->Source();

Example:
                                $cmd = new dbCommand("select * from db", $mysqlconnection->Source());
                            


Set Parameters
$cmd->SetParameter(  String  $param,  String   $value,  $type = null)
This function is used when you use parameterized queries.
Return Void
Parameters $param String; Parameter id
$value Type; Parameter value
$type PDO Parameter type;PDO::Parameter_TYPE.

Example:
                                
    $cmd = new dbCommand("select * from user where status=:status",$myconnnection->Source());
    $cmd->setParameter(":status", "active");
    $data = $cmd->FetchAll();
                                
                            


Fetch All
$cmd->FetchAll();
Fetch all records from returned query
Return Array
Parameters None

Fetch
$cmd->Fetch();
Fetch a single record from returned query
Return Array
Parameters None

Count Rows
$cmd->RowCount();
Count affected rows
Return Integer
Parameters None

Last Inserted Id
$cmd->LastInsertedID();
Return last inserted id
Return Integer
Parameters None

Execute a Command
$cmd->Execute();
Execute the command in constructor.
Return Array
Parameters None