PHPLinq
Upcoming SlideShare
Loading in...5
×
 

PHPLinq

on

  • 1,493 views

MSWDS Session on PHPLinq - www.phplinq.net

MSWDS Session on PHPLinq - www.phplinq.net

Statistics

Views

Total Views
1,493
Slideshare-icon Views on SlideShare
1,489
Embed Views
4

Actions

Likes
0
Downloads
8
Comments
0

1 Embed 4

http://www.slideshare.net 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    PHPLinq PHPLinq Presentation Transcript

    • A lap around PHPLinq
      Introducing PHP Language Integrated Query
      Maarten Balliauw
      http://blog.maartenballiauw.be
      http://twitter.com/maartenballiauw
      maarten@maartenballiauw.be
    • Who am I?
      Maarten Balliauw
      Antwerp, Belgium
      www.realdolmen.com
      Focus on web
      ASP.NET, ASP.NET MVC, PHP, Azure, VSTS, …
      MVP ASP.NET
      http://blog.maartenballiauw.be
      http://twitter.com/maartenballiauw
    • Agenda
      • LINQ?
      • PHPLINQ?
      • Demo
      • Q&A
    • LINQ
      LanguageINtegrated Query
      .NET world (.NET 3.5)
      1 query language
      Multiple providers
      Languageextensions
      Anonymous types
      Object initializer
      Lambdaexpressions
    • LINQ – Example…
      int[] someNumbers = new int[] { 1, 2, 3, 4, 5 };
      var results = from x in someNumberswhere x < 3 select new { Number = x };
      foreach (var result in results) {
      Console.WriteLine(result.Number);
      }
    • PHPLinq
      PHP LanguageIntegrated Query
      PHP userlandlibrary
      1 query language
      Multiple providers
      Featuring
      Anonymous types
      Object initializer
      Lambdaexpressions
    • PHPLinq – Example…
      $someNumbers = newarray(1, 2, 3, 4, 5);
      $results = from('$x')->in($someNumbers) ->where('$x => $x < 3') ->select('new { "Number" => $x }');
      foreach ($results as $result) {
      print($result->Number);
      }
    • PHPLinq providers
    • LinqToObjects
      $employees = array(    new Employee(1, 1, 5, 'Maarten', 'maarten@example.com', 24),    new Employee(2, 1, 5, 'Paul', 'paul@example.com', 30),    new Employee(3, 2, 5, 'Bill', 'bill.a@example.com', 29),    new Employee(4, 3, 5, 'Bill', 'bill.g@example.com', 28),    new Employee(5, 2, 0, 'Xavier', 'xavier@example.com', 40)
      );
      $result = from('$employee')->in($employees)       ->where('$employee => substr($employee->Name, 0, 4) == "Bill"')       ->select('new {               "Name" => $employee->Name,               "Email" => $employee->Email             }');
      Array(    [0] => stdClass Object        (            [Name] => Bill            [Email] => bill.a@example.com        )    [1] => stdClass Object        (            [Name] => Bill            [Email] => bill.g@example.com        ))
    • LinqToZendDb
      class EmployeeTable extends Zend_Db_Table {    protected $_name = 'employees'; // table name    protected $_primary = 'Id';
      }
      $employeeTable = new EmployeeTable(array('db' => $db));
      $employeeTable->setRowClass('Employee');
      $result = from('$employee')->in($employeeTable)       ->where('$employee => substr($employee->Name, 0, 4) == "Bill"')       ->select('new {               "Name" => $employee->Name,               "Email" => $employee->Email             }');
      Array(    [0] => stdClass Object        (            [Name] => Bill            [Email] => bill.a@example.com        )    [1] => stdClass Object        (            [Name] => Bill            [Email] => bill.g@example.com        ))
    • LinqToZendDb – Provider model
      $result = from('$employee')->in($employeeTable)            ->where('$employee => trim($employee->Name) == "Bill"')            ->select('$employee->Name');
      Query on SQLiteSELECT "$employee".* FROM "employees" AS "$employee"WHERE (TRIM('$employee'."Name")  =  "Bill")
      Query on Microsoft SQL ServerSELECT "$employee".* FROM "employees" AS "$employee"WHERE (LTRIM(RTRIM('$employee'."Name"))  =  "Bill")
    • LinqToAzure
      $result = from('$employee')->in( array($azCli, 'employees', 'Employee') )       ->where('$employee => $employee->Name == "Bill"')       ->select('new {               "Name" => $employee->Name,               "Email" => $employee->Email             }');
      Array(    [0] => stdClass Object        (            [Name] => Bill            [Email] => bill.a@example.com        )    [1] => stdClass Object        (            [Name] => Bill            [Email] => bill.g@example.com        ))
    • Parsing XML?
      $rssFeed = simplexml_load_string(file_get_contents('http://blog.maartenballiauw.be/syndication.axd'));
      $result = from('$item')->in($rssFeed->xpath('//channel/item'))        ->orderByDescending('$item => strtotime((string)$item->pubDate)')        ->take(2)        ->select('new {                        "Title" => (string)$item->title,                        "Author" => (string)$item->author                 }');
    • Joining multiple datasources?
      Notofficiallysupported!
    • Questions?
      Check http://phplinq.codeplex.com
      Contact me:
      http://blog.maartenballiauw.be
      maarten@maartenballiauw.be
      http://twitter.com/maartenballiauw
      Thankyou!