Widespread ODBC access from PHP on Linux?

Can someone give me an example query for a Pervasive PSQL database from PHP on a remote Linux machine?

PHP's pervasive claims can access it, but their examples use Windows COM objects that are not available on Linux, and the first PHP DTO Extensions 1 link they download actually refers to a bunch of ASP.NET scripts, and not even PHP: Pervasive PHP Examples

+4
source share
3 answers

I will let Pervasvive know that they need to change the pattern. I have some contacts there. Regarding the use of PSQL from Linux, you will not specify which version of PSQL you are using, but you need a PSQL client for Linux. Here is an example that I used earlier to test the connection from PHP on Linux (and WIndows) to the PSQL server. In odbc_connect, "Demodata" is the DSN ODBC name. The other two parameters are username and password. You will 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
source

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

+1
source

If you can install anything on the Pervasive Server, you can try using odbtp. This is the bridge between the ODBC driver on the server and clients that can run on Linux or Windows. php request example taken from here

 <?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(); ?> 
0
source

Source: https://habr.com/ru/post/1301100/


All Articles