I have to build a php website which has to connect to an Ingres database server.我已经下载了sourceforge pjbs JDBC-PHP桥。我将其安装在项目文件夹中,并尝试连接到我的ingres数据库。我不知道fsockopen()需要哪些参数,对于数据库主机(VMS服务器),我使用vnode,但ingres使用字符串作为端口,而fsockopen需要一个整数。我在Windows 7 Ingres 9.2上使用php 7.2.3在HP OpenVMS v.8.4上使用
<?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;
}发布于 2018-05-22 21:02:39
ingres uses a string as port -将其转换为整数。您可能还应该验证它是否实际返回范围内的数字字符串(对于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正变得非常稀少,您确定没有更高级别的apis可用于Ingres吗?编辑:是的,检查http://php.net/manual/en/book.ingres.php,使用这个扩展几乎肯定比使用原始的tcp套接字容易得多。
https://stackoverflow.com/questions/50468086
复制相似问题