noloh Logo SmallDeveloper Zone
Username:
Password:
remember meforgot password?Login
twitterfacebookirc
plusfolder closePrinciples
plusdocumentWhat is NOLOH?
plusdocumentWhat's so Bad About Markup?
plusdocumentDevelopment and Philosophy
plusfolder closeFeatures
plusdocumentSyntactical Sugars
plusdocumentMultiple Inheritance
plusdocumentBookmarks and NOLOH
plusdocumentUser State Management
plusdocumentSearch Engine Friendly
plusfolder closeGetting Started
plusdocumentPHP and NOLOH Syntax
plusdocumentHello World
plusdocumentConstructors
plusdocumentInstalling NOLOH
plusfolder closeCrash Course
plusdocumentNOLOH and CSS
plusdocumentLayout in NOLOH
plusdocumentDatabases
plusdocumentData::$Links
plusdocumentEvents in NOLOH
plusdocumentMoving and Resizing Your Objects
plusdocumentMultiple Inheritance
plusdocumentBookmarks and NOLOH
plusdocumentData Binding
plusfolder closeAdvanced Topics
plusdocumentCustom Events
plusdocumentClientside Functions
plusfolder closeSyntactic Sugars
plusdocumentSyntactical Sugars
plusdocumentCascading
plusfolder closeCoding Guidelines
plusdocumentBest Practices
plusdocumentNOLOH Naming Conventions
Databases
Databasesoverviewdiscussion

NOLOH facilitates connections to all major commercial and open-source databases and encourages developers to modularize their data handling and has streamlined support for calling views, stored procedures, and prepared statements.

NOLOH has native classes for connecting to MySQL, PostgreSQL, DB2, MSSQLServer, Oracle, and any other ODBC connection. Furthermore, NOLOH can connect to databases other than these using the corresponding PHP (e.g, ADOdb), C, or a native driver for an otherwise unsupported database. You can create a connection to a database either locally, or application-wide. NOLOH recommends that you use the application-wide methods, as it provides for an easy and intuitive way to connect to multiple databases, and execute different kinds of statements with no modifications.

Connections

A database connection can be created a several way: explicitly by using the DataConnection object for your database, or through Data::Links. Using a connection object

Simply instantiate a new DataConnection object and pass in the Data constant that corresponds to your database type.

The generic DataConnection object is instantiated the following way:

/* Database connection parameters:
  databasetype, database name, the user name, password, host, and port*/
$connection = new DataConnection(Data::Postgres, 'somedb', 'someuser', 'somepassword' 'localhost', '5432' ) ;

A connection can be used application wide the following way.

somedb = new DataConnection(Data::Postgres, 'somedb', 'someuser', 'localhost', '5432', 'somepassword') ;

The above method, allows for multiple connections to multiple databases easily throughout your entire application. For instance, you can have multiple connections used in your application in the following way.

//My somedb connection that talks to my PostgreSQL somedb database.
Data::$Links->somedb = new DataConnection(Data::Postgres, 'somedb', 'someuser', 'somepassword'  'localhost', '5432');
//My otherdb connection that talk to a MySQL otherdb database.
Data::$Links->otherdb= new DataConnection(Data::MySQL,'otherdb', 'someuser', 'somepassword'  'localhost', '5432');

See Data::$Links documentation for more information on streamlined and intuitive data communication executed easily throughout your application.

Commands

In NOLOH, database commands consist of the SQL that will be executed. After execution they will return the results in a DataReader object that corresponds to your database type. Using the Data::Links method we mentioned earlier allows you to completely bypass using commands.

However, if you need to use a command, they're used in the following manner:

//Where $connection is a Connection object, and $SQLStatement is a SQL statement
$cmd = new DataCommand($connection, $SQLStatement)

To demonstrate more clearly:

$conn =  new  DataConnection('somedb', 'someuser',  'localhost', '5432', 'somepassword');
$query = 'SELECT * FROM sometable WHERE sometable_id = 1';
$cmd =  new DataCommand($conn, $query);

Now that the DataCommand is created, it can be executed as follows. It will NOT be executed unless you explicitly execute it.

$cmd->Exec();

If you're retrieving results from the query, you'll want to set a variable to retrieve the results.

$results = $cmd->Exec();

Furthermore, if you want to limit the way in which your results return you can pass this in to Execute(). For instance, if you only wanted your results to be returned associatively, you would pass in Data::Assoc:

$results = $cmd->Exec(Data::Assoc);

If you wanted only numerical indices for your columns you would pass in Data::Num:

$results = $cmd->Exec(Data::Num);

The default is to return the results in both associative, and numerical indices, which is our above examples is equivalent to Data::Both

$cmd->Exec() //returns a DataReader Object

Data Readers

A DataReader object retrieves the information from a Command and stores in its Data array. The data can be accessed directly through [], or through ->Data[]:

$results = $cmd->Execute();

$name = $results[0]['somename']

or

$name = $results->Data[0]['somename']

Data[0]['somename'] corresponds to the row of data

Data[0]['somename'] corresponds to the column name.

If the result type were set to Data::Num you would need to specify the number that corresponds to the desired column:

Data[0][1]

Because the Data is an array you can easily loop through it. So, a more practical example would be:

foreach($results->Data as $result)
    Alert($result['somename']);
smallarrow
explanation arrowtool tip
handlebgexpand left
Right Up Outer CornerRight Down Outer CornerLeft Up Outer CornerLeft Down Outer Cornersearch-bottomclassconstantpropertymethodarticle
controltabsearchbig