user898082
user898082

Reputation:

PHP sql anywhere connection issues

I want to access a remote Sybase Database with PHP and the module SQLANYWHERE. 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:

$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"

EDIT: These are all the different connStrings i already tried:

$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. 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 "??". after rewriting the part where the characters were, the connection works. kill me... 2 days for this.

Upvotes: 0

Views: 2323

Answers (2)

I think this is a problem with connecting to database. Just try run your sqlanywhere database like this:

./bin64/dbeng17 -x tcpip /path/to/database/database.db

This trigger "-x tcpip" is important to connect php with database.

Upvotes: 0

dsh
dsh

Reputation: 11

The error is pretty self explanatory; What is at line 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.

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:

$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.

Upvotes: 1

Related Questions