Connecting with PHP to Sybase on WAMP Server
Sybase is one of those systems that can be sometimes finicky to setup on the client side. I was pleasantly surprised to see that PHP has support for Sybase. When you need to quickly prototype a new feature or give your user’s a quick dynamic report, PHP can be a great path to go.
It took a little research to get all the parts necessary, but the installation is very smooth.
- Install WAMP
- Install Sybase client (you want the open client; login/pass required)
- Update php.ini to: enable sybase extension (extension=php_sybase_ct.dll)
- specify location of sybase sql.ini file (sybase.interface_file = “c:\sybase\ini\sql.ini”)
To test the connection we can do a simle query against a table:
<?php
<html>
<head>
<title>Sybase Test</title>
</head>
<body>
Testing execution<br />
<?= print_sybase_version() ?>
</body>
</html>
<?php
function print_sybase_version(){
sybase_min_server_severity(20);
$connection = sybase_connect('<server_alias>', '<username>', '<password>');
if(!$connection){
echo "couldn't make a connection";
}else{
$sql = "select CUSTOMER_NAME, CUSTOMER_STATUS from CUSTOMER order by CUSTOMER_NAME";
$sql_result = sybase_query($sql, $connection);
print "<table border=\"1\">";
while($row = sybase_fetch_array($sql_result)){
$name = $row["CUSTOMER_NAME"];
$status = $row["CUSTOMER_STATUS"];
print "<tr><td>$name></td><td>$status</td></tr>";
}
print "</table>";
}
}
?>