<html>
<head>
<title> CSPP552: Internet Programming: PHP</title>
</head>
<body bgcolor="#ffffff">
<h1> CSPP552: Internet Programming, PHP part 8</h1>

<h2>Access to Sybase databases with PHP</h2>

<ul>
<li>You may have already seen something similar to this with Sybase in Leo's
class
<li>Function names begin with <tt>sybase_</tt>
<li>Connect with <tt>sybase_connect()</tt>; arguments are serverhost, user, and
password:<br>
<tt>$connection = sybase_connect("skunk", "bri", "blahblah");</tt>
<li>Select a database with <tt>sybase_select_db()</tt>:<br>
<tt>sybase_select_db("<em>database_name</em>", $connection);</tt>
<li>Run some SQL command with <tt>sybase_query()</tt>:<br>
<tt>$result = sybase_query("<em>SQL_command</em>", $connection);</tt>
<li>Grab a row with <tt>sybase_fetch_array()</tt>:<br>
<tt>$row = sybase_fetch_array($result);</tt>
<li>In the above, access fields with <tt>$row["fieldname"]</tt>.
etc.
<li><tt>$row</tt> evaluates to `false' when there are no more rows to
fetch.
<li>Don't use <tt>sybase_fetch_row()</tt>, seems to be a bug somewhere if
you have too many fields.
</ul>

Example:
<br>
<table width=100% border=1>
<tr>
<td valign=top>
<pre>
&lt;?php
 $c = sybase_connect("skunk", "bri", "blahblah");
 sybase_select_db("pubs2", $c);
 $stuff = sybase_query("select * from titles");
 while ($row = sybase_fetch_array($stuff)) {
    print "$row[title] ..... \$$row[price]&lt;br&gt;";
 }
?&gt;
</pre>
</td><td>
<?php
 $c = sybase_connect("skunk", "bri", "blahblah");
 sybase_select_db("pubs2", $c);
 $stuff = sybase_query("select * from titles");
 while ($row = sybase_fetch_array($stuff)) {
    print "$row[title] ..... \$$row[price]<br>";
 }
?>
</td>
</tr></table>

<br>

<hr>
</body>
</html>
