'Use PHP variable in SPARQL?

$abc=$_GET["q"];

$store = ARC2::getStore($arc_config);

         $p = '
           SELECT DISTINCT ?property WHERE { 
           ${"abc"} ?property ?object .
        }
    ';

I want to retrieve properties whose subject is equal to $abc (PHP variable) via GET method. But I am facing problems. I am using ARC2 as RDFStore and SPARQL to retrieve and PHP.



Solution 1:[1]

Common string operations

For example

$p = sprintf('
       SELECT DISTINCT ?property WHERE { 
       %s ?property ?object .
    }
', $abc);

or

$p = "
       SELECT DISTINCT ?property WHERE { 
       $abc ?property ?object .
    }
";

or

$p = '
       SELECT DISTINCT ?property WHERE { 
       ' . $abc . ' ?property ?object .
    }
';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KingCrunch