Pervasive ODBC access from PHP on Linux?

前提是你 提交于 2019-12-12 11:26:53

问题


Can anyone give me an example of querying a Pervasive PSQL database from PHP on a remote Linux machine?

Pervasive claims PHP can access it, but their examples use Windows COM objects, which isn't available on Linux, and the first "PHP DTO Extensions 1" link they have for download actually links to a bunch of ASP .NET scripts, and isn't even PHP at all: Pervasive PHP Examples


回答1:


I'll let Pervasvive know they need to change the sample. I've got some contacts there. As for using PSQL from a Linux box, you don't mention what version of PSQL you are using but you'll need the PSQL client for Linux. Here's a sample I've used before to test connectivity from PHP on Linux (and WIndows) to a PSQL server. In the odbc_connect, the "Demodata" is the ODBC DSN name. The other two parameters are user name and password. You would need to compile (or enable) ODBC in PHP.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>PHP Sample</TITLE>
</HEAD>
<BODY>
<?php
$conn=odbc_connect("Demodata","","",""); 
$sql="select * from class";
$rs=odbc_exec($conn,$sql);  
echo "<table border=1>\n";
$numfields = odbc_num_fields($rs);
for($i=1;$i<=$numfields;$i++){
    $fn=odbc_field_name($rs,$i);
    echo "<th>$fn</th>";
}
echo "\n";
while(odbc_fetch_row($rs)){ 
    echo "<tr>\n";
    for($i=1;$i<=$numfields;$i++){
       $fv=odbc_result($rs,$i);
       echo "<td>$fv</td>";
    }   
    echo "</tr>\n";
} 
echo "</table>\n";
echo "<p>Number of Fields: $numfields</p>\n";
?>
</BODY>
</HTML>



回答2:


I think what you need is the PDO extension http://nl.php.net/manual/en/pdo.installation.php it can connect to any database which supports ODBC




回答3:


If you can install something on the Pervasive Server you can try using odbtp. It is a bridge between an ODBC driver on the server and clients that can run on Linux or Windows. a query example from php taken from here is

<?php

$con = odbtp_connect( 'odbtp.somewhere.com',
                      'DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=mydb;' ) or die;

odbtp_set_attr( ODB_ATTR_FULLCOLINFO, TRUE );

$qry = odbtp_query( $_REQUEST['query'] ) or die;

do {
    if( ($msg = odbtp_get_message( $qry )) ) {
        echo "MESSAGE: $msg<p>";
        continue;
    }
    if( ($cols = odbtp_num_fields( $qry )) == 0 ) {
        echo odbtp_affected_rows( $qry );
        echo " rows affected<p>\n";
        continue;
    }
    echo "<table cellpadding=2 cellspacing=0 border=1>\n";
    echo "<tr>";
    for( $col = 0; $col < $cols; $col++ ) {
        echo "<td><nobr> " . odbtp_field_name( $qry, $col );
        echo " (" . odbtp_field_type( $qry, $col ) . ") </nobr></td>";
        if( odbtp_field_bindtype( $qry, $col ) == ODB_DATETIME )
            odbtp_bind_field( $qry, $col, ODB_CHAR );
    }
    echo "</tr>\n";

    while( ($rec = odbtp_fetch_array($qry)) ) {
        echo "<tr>";
        for( $col = 0; $col < $cols; $col++ ) {
            if( is_null( $rec[$col] ) ) $rec[$col] = "NULL";
            echo "<td><nobr> $rec[$col] </nobr></td>";
        }
        echo "</tr>\n";
    }
    echo "</table><p>\n";

    echo odbtp_affected_rows( $qry );
    echo " rows affected<p>\n";
}
while( odbtp_next_result( $qry ) );

odbtp_close(); ?>


来源:https://stackoverflow.com/questions/2251334/pervasive-odbc-access-from-php-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!