• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1305
  • Last Modified:

php sybase adaptive server anywhere

We have an application that runs using a sybase adaptive anywhere database.

How can I connect to this database using php, run an SQL query and return the results?

Kind regards
0
antonioking
Asked:
antonioking
  • 5
  • 5
1 Solution
 
Jan FranekCommented:
0
 
antoniokingAuthor Commented:
Hi thanks Jan..

Unfortuantely our server is version 9 so the link is unapplicable.
We are not in a position to upgrade the version either.

Are there not other methods to run SQL queries on the db?
0
 
Jan FranekCommented:
SQL Anywhere instalation includes GUI client called Interactive SQL and command line client dbisql. They can be used to run queries on the db.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Jan FranekCommented:
If you don't have these clients from your SQL Anywhere instalation, you may try to dowload client for new version (http://www.sybase.com/detail?id=1087327) - I believe, it should be backward compatible (however, I didn't try it myself).
0
 
antoniokingAuthor Commented:
Hi Jan,

I'm aware of the Interactive SQL client. But that doesn't help me run queries using php?
0
 
Jan FranekCommented:
Well, I didn't see word php in your question "Are there not other methods to run SQL queries on the db?"
0
 
antoniokingAuthor Commented:
...

Are there not other methods to run SQL queries on the db USING PHP?
0
 
Jan FranekCommented:
I can see directory src/php in my SQL Anywhere 9 instalation and it seems like php module is shipped with SQL Anywhere since version 9.0.2 (see http://php.net/manual/en/ref.sybase.php).

Another way is to use PHP module for ASE - it should work with Anywhere too.

Third option (but I'm not sure if it is supported on version 9) is to create web service and access Anywhere database through http interface - that way you probably don't need any php module at all.
0
 
antoniokingAuthor Commented:
I have found my own solution...

Add a dsn connection in ODBC to the sybase db then used the code below...
<?php
//================================================================

  // Configure connection parameters
  $db_host        = "SERVER.DOMAIN";
  $db_server_name = "DBSERVERNAME";
  $db_name        = "DBNAME";
  $db_file        = 'DBFILELOCATION';
  $db_conn_name   = "php_script";
  $db_user        = "USERNAME";
  $db_pass        = "PASSWORD";

//================================================================
  $connect_string = "Driver={Adaptive Server Anywhere 9.0};".
                    "CommLinks=tcpip(Host=$db_host);".
                    "ServerName=$db_server_name;".
                    "DatabaseName=$db_name;".
                    "DatabaseFile=$db_file;".
                    "ConnectionName=$db_conn_name;".
                    "uid=$db_user;pwd=$db_pass";

  // Connect to DB
  $conn = odbc_connect($connect_string,$db_user,$db_pass);
  if (!$conn) {
    die('Could not connect: ' . mysql_error());
  }

  // Query
  $qry = "SELECT ref, first_name, last_name FROM person WHERE person_ref=1";

  // Get Result
  $result = odbc_exec($conn,$qry);
  if (!$result) {
    die('Query failed: ' . mysql_error());
  }

  while(odbc_fetch_row($result)){
    $ref = odbc_result($result, ref);
    $name = odbc_result($result, first_name);
    $surname = odbc_result($result, last_name);

    print("$ref $name $surname\n");
  }

  // Close Connection
  odbc_close($conn);

//================================================================
?>

Open in new window

0
 
antoniokingAuthor Commented:
Own solution that works
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now