PHPackages                             legrand/sparql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. legrand/sparql

ActiveLibrary

legrand/sparql
==============

Library that generate SPARQL queries and request a endpoints

31012[1 issues](https://github.com/snoozeman/sparql-php/issues)PHP

Since Jan 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/snoozeman/sparql-php)[ Packagist](https://packagist.org/packages/legrand/sparql)[ RSS](/packages/legrand-sparql/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SPARQL for PHP
==============

[](#sparql-for-php)

A library that generate SPARQL queries and request a endpoints

Exemple
-------

[](#exemple)

A quick and easy sparql request to understand how it works. You can find more exemples in the SparqlTest.php file.

```
    $sparql = new Legrand\SPARQL;

    $sparql->variable('?z')
           ->where('', '?y', '?z')
           ->limit(20);

    $response = $sparql->launch();

```

Methods
-------

[](#methods)

- `prefixe($namespace, $url)` You can add several prefixes with this method
- `distinct($boolean)` Set a request with a distinct select
- `variable($var)` Add a variable to select i.e. `?z`
- `from($graph)` Add a from graph i.e. `http://graph`
- `where($subject, $predicate, $object)` add a where condition
- `optionalWhere($subject, $predicate, $object)` add a conditional where condition
- `optionalWhereComplexe($sparql)` add a more complex conditional where in the query
- `union($sparql)` define where condition on a SPARQL object and give it to this method
- `filter($filter)` add a filter inside the where brackets
- `orderBy($order)` define the order i.e. `?z DESC`
- `limit($nb)` define the limit
- `offset($nb)` define the offset
- `insert($graph)` create an insert sparql query by giving the graph uri
- `delete($graph)` create a delete sparql query by giving the graph uri
- `getSPARQL()` get the SPARQL query without calling the endpoint

Defaults
--------

[](#defaults)

Some attributes are set with defaults value. You can of course change these values :

- `$sparql->baseUrl = 'http://dbpedia.org/sparql';`
- `$sparql->format = 'json';`
- `$sparql->method = 'GET';`
- `$sparql->queryParam = 'query';`
- `$sparql->formatParam = 'format';`

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4514bc375621b8b7ac86b16a3a130c079d1393dfdc699c98d634406010fbc955?d=identicon)[damien\_legrand](/maintainers/damien_legrand)

---

Top Contributors

[![legranddamien](https://avatars.githubusercontent.com/u/379301?v=4)](https://github.com/legranddamien "legranddamien (13 commits)")[![kinow](https://avatars.githubusercontent.com/u/304786?v=4)](https://github.com/kinow "kinow (2 commits)")

### Embed Badge

![Health badge](/badges/legrand-sparql/health.svg)

```
[![Health](https://phpackages.com/badges/legrand-sparql/health.svg)](https://phpackages.com/packages/legrand-sparql)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
