Matthew Tedder wrote:
Ok..
Maybe I am seeing how it works now. I am not used to ODBC (usually, mysql,
postgresql, or mssql) and saw various examples under google searches
explicitly stating the database driver with such as "driver=..." in the odbc
connect statements.
Also.. I apologize if my email sounded a bit negative. I didn't mean it to..
Thank you for responding. I really do appreciate it.
I will try what you wrote below...
Matthew
Our fundamental concern is that DBMS independence via ODBC is now
somewhat forgotten.
Not understanding ODBC takes data access back many years, in the wrong
direction.
LAMP espouses a very sad monoculture by promoting MySQL specificity at
the expense of ODBC enabled DBMS independence.
Putting passwords in PHP files is a great example of how this kind of
monoculture leads to serious problems such as security holes via SQL
Injection in addition to making solutions DBMS specific (which is good
for MySQL and bad for everyone else).
Remember, MySQL is accessible via ODBC Drivers from various sources
(ourselves included). Like many things today, promoting ODBC data over
MySQL DBMS specific data access doesn't mean anyone dislikes MySQL. We
just totally dislike monoculture at OpenLink Software :-)
Kingsley
-----Original Message-----
From: Patrick van Kleef [mailto:[email protected]]
Sent: Monday, August 02, 2010 4:30 AM
To: Matthew Tedder
Cc: [email protected]
Subject: Re: [Virtuoso-users] Examples of how to connect SQL from PHP (under
apache)?
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
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Virtuoso-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/virtuoso-users
--
Regards,
Kingsley Idehen
President & CEO
OpenLink Software
Web: http://www.openlinksw.com
Weblog: http://www.openlinksw.com/blog/~kidehen
Twitter/Identi.ca: kidehen