我无法使用php 7连接到Ingres

时间:2018-05-22 12:45:19

标签: php ingres

I have to build a php website which has to connect to an Ingres database server.

我已经下载了sourceforge pjbs JDBC-PHP桥。 我在项目文件夹中安装了它,并尝试连接到我的ingres数据库。我不明白fsockopen()需要哪些参数,对于我使用vnode的数据库主机(VMS服务器),但是ingres使用字符串作为端口,而fsockopen想要一个整数。 我用 Windows 7上的php 7.2.3 HP OpenVMS v.8.4上的Ingres 9.2

<?php

require "lib/PJBridge.php";

function get_connection()
{
    $connStr = "jdbc:ingres://vnode:II7/dbname";

    $db = new PJBridge();
    $result = $db->connect($connStr, $user, $password);

    if(!$result){
        die("Failed to connect");
}
return $result;}


<?php
class PJBridge {

    private $sock;
    private $jdbc_enc;
    private $app_enc;

    public $last_search_length = 0;

    function __construct($host="vnode", $port=-1, $jdbc_enc="ascii", $app_enc="ascii") {

        $this->sock = fsockopen($host, $port);

        $this->jdbc_enc = $jdbc_enc;
        $this->app_enc = $app_enc;
}

1 个答案:

答案 0 :(得分:0)

ingres uses a string as port - 然后将其转换为int。您可能还应该验证它实际上返回范围内的数字字符串(对于ipv4和ipv6,有效端口范围是1-65535。(端口0也存在但在大多数系统上不可用))

$port = "9999";
$old = $port;
if (false === ($port = filter_var ( $port, FILTER_VALIDATE_INT, array (
        'options' => array (
                'min_range' => 1,
                'max_range' => 65535 
        ) 
) ))) {
    throw new \LogicException ( "port is not a valid integer in range 1-65535! ($old)" );
}
// here, $port is guaranteed to be an int in range 1-65535.

对于socket_connect想要的选项,请查看此示例,在端口80上连接到example.com以下载html网站:

$fp = fsockopen ( "www.example.com", 80, $errno, $errstr, 30 );
if (! $fp) {
    echo "error connecting: $errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite ( $fp, $out );
    while ( ! feof ( $fp ) ) {
        echo fgets ( $fp, 128 );
    }
    fclose ( $fp );
}

全部来自the fsockopen documentation.

作为最后一点,我对Ingres没有任何经验,但是原始tcp apis变得极为罕见,你确定Ingres没有更高级别的apis吗?编辑:是的,检查http://php.net/manual/en/book.ingres.php,使用该扩展几乎肯定比使用原始tcp套接字容易