PHP sql anywhere连接问题
我想用PHP和SQLANYWHERE模块访问远程Sybase数据库。我安装了它,并测试它是否能正常工作,如下所示:PHP sql anywhere连接问题,php,sybase,sqlanywhere,Php,Sybase,Sqlanywhere,我想用PHP和SQLANYWHERE模块访问远程Sybase数据库。我安装了它,并测试它是否能正常工作,如下所示: if( ! extension_loaded('sqlanywhere') ) print("<b>SQL ANYWHRE not available</b>". "\xA") ; $host = 'xxx.xxx.xxx.xxx'; $port = xxxx; $waitTimeoutInSeconds = 1; if($fp = fsockop
if( ! extension_loaded('sqlanywhere') ) print("<b>SQL ANYWHRE not available</b>". "\xA") ;
$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);
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.":".$port.")";
./bin64/dbeng17 -x tcpip /path/to/database/database.db
所有值都已正确配置,因为它在上面的第一次尝试中起作用
但当我尝试加载我的页面时,总是会出现以下错误:
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
第一行表示“连接错误:TCPIP端口选项中的错误”
编辑:这些都是我已经尝试过的不同字符串:
$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.")";
解决方案
我发现PHP模块所需的SQLAnywhere安装有一个名为include的cmdline工具。将字符串从文本编辑器复制到cmdline时,我注意到字符串中存在cmdline无法解析的不可打印字符,并将其打印为“?”。在重写字符所在的部分后,连接工作。杀了我。。。2天。这个错误是不言自明的;第59行是什么?是这条线吗
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.";port=".$port.")";
基本上,您的端口不正确。您还试图对不存在的对象调用close()
方法
我阅读了一些文档(),您的字符串看起来应该是这样的:
if( ! extension_loaded('sqlanywhere') ) print("<b>SQL ANYWHRE not available</b>". "\xA") ;
$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);
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.":".$port.")";
./bin64/dbeng17 -x tcpip /path/to/database/database.db
请注意,这会将端口附加到主机(主机:1337),而不是给它一个显式的
port
键。我认为这是连接到数据库的问题。
只需按以下方式运行sqlanywhere数据库:
if( ! extension_loaded('sqlanywhere') ) print("<b>SQL ANYWHRE not available</b>". "\xA") ;
$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);
$connString = "Uid=".$username.";Pwd=".$password.";CommLinks=tcpip(host=".$server.":".$port.")";
./bin64/dbeng17 -x tcpip /path/to/database/database.db
这个触发器“-x tcpip”对于连接php和数据库很重要。警告:sasql_connect():SQLAnywhere:[-832]Verbindungsfehler:Fehler在den tcpip Portoptionen中你能把它翻译成英语吗?我问题的最后一句是翻译:)哦,对不起,没有看到:)那么,你在这里有问题了
CommLinks=tcpip(主机)=“$server.”port=“.$port.”“;
,更具体地说,这里是$port
。您是否检查了SqlAnywhere文档,了解可能的故障排除?我真的不知道要查找什么,端口是打开的,我可以从运行代码的机器上访问它,文档说错误代码-832代表“连接问题”“。文档中关于错误的信息比错误消息中的信息要少。是的,第59行是调用connString
的位置。端口是正确的,我使用它通过另一个工具连接到DB服务器,值是正确的。我尝试使用您的connString,但将端口附加到主机也没有帮助。进一步阅读我提供的文档,您使用CommLinks
参数而不是Host
参数有什么原因吗?如果您找到了解释此过程的文档,请给我一个链接。我找到了与您使用的CommLinks键对应的推荐方法:请参阅相关更新,获得解决方案。无论如何,谢谢你:)