Project Description
LINQ for PHP is a class a PHP Class library that emulates the C# LINQ library we all have come to love. Includes connection and class type-mapping to and from mysql. Development is in progress. Please let me know what you think!

Basic Use & Data Mapping

The Data Context

You must first create a data context to connect to mysql.

// require the lib file
// Setup a data context
LINQ_MYSQL::Create_Context($host, $user, $pass, $db);

LINQ Queries

Each statement in the query must follow this format (' KEY => Value')

Where statements should follow this format ('WHERE => whereKey :==: whereValue')
The operand should be surrounded by colons.

// Retrieve a result from a LINQ query
$result = LINQ_MYSQL::LINQ('
                              SELECT => Product,
                              FROM => Products,
                              ORDER BY => id ASC,
                              WHERE => id :>: 1

foreach($result as $product)
    echo $product->get_productName();

Class Setup

If the statement after SELECT => is not a class name, a standard mysql result will be returned; else it will data map to the particular class

class Product
     // Auto Increment fields should be protected
    protected $id; 
    public $productName;
    public $price;
    public function set_id($id)
        $this->id = $id;
    public function get_id()
        return $this->id;
    public function set_productName($productName)
        $this->productName = $productName;
    public function get_productName()
        return $this->productName;
    public function get_price()
        return $this->price;
    public function set_price($price)
        $this->price = $price;

Inserting Using Class Objects

$myProduct =  new Product();

LINQ_MYSQL::Insert("Products", $myProduct);

Deleting Using Class Objects

If you have a populated class object or array, you can pass it to the Delete Method

$product; // My populated class object
LINQ_MYSQL::Delete("Products", $product);

Updating Using Class Objects

If you need to update the class do the following

LINQ_MYSQL::Update("Products", $product, "id"); // Third parameter is a where key.  Where id = $product->get_id()

Last edited Sep 18, 2010 at 2:34 PM by dklompmaker, version 10