[英]PHP sql anywhere connection issues
I want to access a remote Sybase Database with PHP and the module SQLANYWHERE. 我想使用PHP和模块SQLANYWHERE访问远程Sybase数据库。 I installed it and tested that it worked properly like this:
我安装了它,并测试它是否可以像这样正常工作:
if( ! extension_loaded('sqlanywhere') ) print("<b>SQL ANYWHRE not available</b>". "\xA") ;
I then tried if I can even reach the DB-Server like this: 然后,我尝试是否可以像这样到达DB-Server:
$host = 'xxx.xxx.xxx.xxx';
$port = xxxx;
$waitTimeoutInSeconds = 1;
if($fp = fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)){
print("<b> SQL Verbindung established</b>". "\xA");
} else {
print("<b>keine SQL not established</b>". "\xA");
}
fclose($fp);
which also worked. 这也起作用。 But I just can't connect, here is my connection string:
但是我无法连接,这是我的连接字符串:
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.";port=".$port.")";
$conn=sasql_connect($connString);
all the values are correctly configured since it worked in the first try above. 所有值均已正确配置,因为它已在上面的第一次尝试中起作用。
But when I try to load my page I always get this error: 但是,当我尝试加载页面时,总是会出现此错误:
Warning: sasql_connect(): SQLAnywhere: [-832] Verbindungsfehler: Fehler in den TCPIP Portoptionen in C:\xampp\htdocs\index.php on line 59
sasql_connect failed
Fatal error: Call to a member function close() on boolean in C:\xampp\htdocs\index.php on line 75
the first line means "Connection Error: Error in the TCPIP port options" 第一行表示“连接错误:TCPIP端口选项中的错误”
EDIT: These are all the different connStrings i already tried: 编辑:这些都是我已经尝试过的所有不同的connStrings:
$connString = "Uid=".$username.";Pwd=".$password.";Server=".$serverName.";host=".$server.":".$port.")";
$connString = "Uid=".$username.";Pwd=".$password.";host=".$server.":".$port.")";
$connString = "Uid=".$username.";Pwd=".$password.";host=".$server.";port=".$port;
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.":".$port.")";
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server."Port=".$port.")";
SOLUTION 解
I found out that the SQL Anywhere installation you need for the PHP module has a cmdline tool called dbping included. 我发现,PHP模块所需的SQL Anywhere安装包含一个名为dbping的cmdline工具。 copying my string from my text editor to the cmdline i noticed there where unprintable characters in my string which the cmdline couldn't resolve and printed them as "??".
将我的字符串从文本编辑器复制到cmdline时,我注意到那里的字符串中无法打印的字符cmdline无法解析,并将它们打印为“ ??”。 after rewriting the part where the characters were, the connection works.
重写字符所在的部分后,连接有效。 kill me... 2 days for this.
杀了我...为此2天。
The error is pretty self explanatory; 该错误很容易解释。 What is at line 59?
59行是什么? Is that this line:
是这一行:
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.";port=".$port.")";
Essentially your port isn't correct. 本质上,您的端口不正确。 You are also trying to call the
close()
method on an object that doesn't exist. 您还试图在不存在的对象上调用
close()
方法。
I read through some documentation ( http://dcx.sybase.com/1200/en/dbadmin/links.html ) and it looks like your string should actually look like this: 我通读了一些文档( http://dcx.sybase.com/1200/en/dbadmin/links.html ),看起来您的字符串实际上应该像这样:
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.":".$port.")";
Note that this appends the port to the host (host:1337), instead of giving it an explicit port
key. 请注意,这会将端口附加到主机(host:1337),而不是为其提供显式的
port
密钥。
I think this is a problem with connecting to database. 我认为这是连接数据库的问题。 Just try run your sqlanywhere database like this:
只需尝试像这样运行您的sqlanywhere数据库:
./bin64/dbeng17 -x tcpip /path/to/database/database.db
This trigger "-x tcpip" is important to connect php with database. 此触发器“ -x tcpip”对于将php与数据库连接很重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.