Useful PHP script – running queries against sybase database

Problem

you want to run queries against a Sybase Database, using the PHP API.



Solution

A PHP script using sybase API for PHP, connect as given user, with your password on specific host.



Example


Useful for monitoring sybase dbs, although in this instance it does not actually hit any database tables.

<?php

$user = "your_user";
$passwd = "password";
$host = "your_host";
$sql="select getdate(), @@version ";
$conn=sybase_connect($host,$user,$pass); // connect to db
print("running query host: $hostnuser: $usern");
$result = sybase_query ( $sql ); // Run query and store in array
$i = 0;
while($row = sybase_fetch_array($result)) {
// Loop around the array and print field or column 1 and 2
$i++;
$item1 = $row[0];
$item2 = $row[1];
echo "$i $item1 $item2";
}
sybase_close();
?>



Reference

[tags]Sybase PHP example, PHP Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *