HI Matthew,


Thank you for trying to point me toward help but I am still at a loss at how to connect to Virtuoso from PHP under Apache. I cannot use Virtuoso as a webserver for lack of Shibboleth support and so __virt_internal_dsn() is of no use to me. It might be possible to build a hybrid apache/mysql/ php and virtuoso/php application (separated the public and secure areas, accordingly)
and using web services between the two.


The _virt_internal_dsn() function is only usable when you use the internal hosted version of PHP as this provides an extra security layer as you do not have to put the password inside your .php source file, which normally needs to be changed very time you change your dba password. If you had looked beyond that fact, you would have noticed the page uses standard odbc_connect calls to make a connection.

You can use any Apache/PHP combination from your favorite distribution as long as it is build with ODBC support which is normally built into any Linux disto and many others. In some cases PHP ODBC support is an optional package which you need to install.

There is no other difference between running Virtuoso/PHP and Apache/ PHP/Virtuoso from a programming point of view.


There has got to be some way to do this.. some documentation somewhere.. I cannot imagine that the only way for a php app to connect is by running
under virtuoso's webserver, lacking such a wealth of capabilities.

I am getting pretty tired of searching, reading, testing ideas, and coming
up empty-handed.  There must be some way.

As said in my previous mail, Virtuoso uses the ODBC API for connections. This means that any programming language that has an ODBC binding can use it. Many languages like perl, php, python, ruby etc have a working ODBC layer either build in, or through an extension package. This layer uses one of the ODBC Driver Managers like iODBC or unixODBC to connect with any target database through a specific ODBC Driver, in this case using the virtodbc_r.so driver.

There is plenty of documentation on making an ODBC connection to PHP, available on both the PHP site and others.


Very simply put:

1. Create an ODBC DSN

Edit the file /etc/odbc.ini and add the following data there (obviously putting the full pathname
   to your virtodbc_r.so file into this line)


        [Local Virtuoso]
        Driver  = /path/to/your/lib/virtodbc_r.so
        Address = localhost:1111


2. Create a sample php script like below and put this into your apache directory:

   <html>
   <body>

   <?php
    // Make a connection
    $conn=odbc_connect('Local Virtuoso','dba','dba');
    if (!$conn) {exit("Connection Failed: " . $conn);}

    // Get a list of tables
$sql="select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME from INFORMATION_SCHEMA.TABLES";
    $rs=odbc_exec($conn,$sql);
    if (!$rs) {exit("Error in SQL");}

    //  Show results in a table
    echo "<table><tr>";
    echo "<th>Catalog</th>";
    echo "<th>Schema</th>";
    echo "<th>Table Name</th></tr>";

    while (odbc_fetch_row($rs))
    {
        $catname=odbc_result($rs,"TABLE_CATALOG");
        $schemaname=odbc_result($rs,"TABLE_SCHEMA");
        $tablename=odbc_result($rs,"TABLE_NAME");
        echo "<tr><td>$catname</td>";
        echo "<td>$schemaname</td>";
        echo "<td>$tablename</td></tr>";
    }
    echo "</table>";

    // Close connection
    odbc_close($conn);
   ?>

   </body>
   </html>


3. Connect with your browser to the created URL and you should get a list of tables.



I hope this information help you get your project on track, if not sufficient, please let me know.


Best regards,

Patrick

Reply via email to