Quantcast
Channel: SCN: Message List - SAP Adaptive Server Enterprise (SAP ASE) for Custom Applications
Viewing all articles
Browse latest Browse all 3587

Re: Using PHP to connect via the ODBC driver

$
0
0

Hi Dawn,

 

Thanks a lot for your help! Unfortunately us traditional SAP'ers dont get to ISUG

 

So I finally got it working.  There is a package called "php5-sybase" (duh) that you can install with a simple:

   

'sudo apt-get install php5-sybase'

 

After that, you can use the standard PDO class for connecting!!!

 

Below is sample code to get anyone started:

 

<!doctype html>

  <body>

    <?php

      try {

        $hostname = "Ubuntu1";

        $port = 5000;

        $dbname = "tempdb";

        $username = "sa";

        $pw = "password";

        $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");

      } catch (PDOException $e) {

        echo "Failed to get DB handle: " . $e->getMessage() . "\n";

        exit;

      }

      $stmt = $dbh->prepare("select name from master..sysdatabases");

      $stmt->execute();

      $databases = $stmt->fetchAll();

    ?>

 

 

    <table>

      <thead>

        <tr>

          <th>Database</th>

        </tr>

      </thead>

      <tbody>

        <?php

        foreach ( $databases as $database ) {

          echo "<tr>";

          echo "<td>" . $database[0] . "</td>";

          echo "<tr>";

        }

        ?>

      </tbody>

    </table>

  </body>

</html>

 

 

This will output the following to your web browser:

 

Database
master
model
sybmgmtdb
sybsystemdb
sybsystemprocs
tempdb

Viewing all articles
Browse latest Browse all 3587

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>