English 中文(简体)
Pervasive ODBC access from PHP on Linux?
原标题:

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

问题回答

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>
";
$numfields = odbc_num_fields($rs);
for($i=1;$i<=$numfields;$i++){
    $fn=odbc_field_name($rs,$i);
    echo "<th>$fn</th>";
}
echo "
";
while(odbc_fetch_row($rs)){ 
    echo "<tr>
";
    for($i=1;$i<=$numfields;$i++){
       $fv=odbc_result($rs,$i);
       echo "<td>$fv</td>";
    }   
    echo "</tr>
";
} 
echo "</table>
";
echo "<p>Number of Fields: $numfields</p>
";
?>
</BODY>
</HTML>

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

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>
";
        continue;
    }
    echo "<table cellpadding=2 cellspacing=0 border=1>
";
    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>
";

    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>
";
    }
    echo "</table><p>
";

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

odbtp_close(); ?>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签