Hi, I am trying to connect a
php website to a database and display the contents.
But I am getting a blank page (no error messages) instead.
I have one file called odbc.
php, that I'm pretty sure makes a connection to the database, with this code:
- PHP: Select all
<html>
<body>
<?php
$odbc = odbc_connect ('testDB', 'root', '') or die ('Could not connect');
if ($odbc != 0) echo ('Connection made!');
if(!function_exists('odbc_fetch_array'))
{
function odbc_fetch_array($result, $rownumber=-1)
{
if (PHP_VERSION > '4.1')
{
if ($rownumber < 0)
{
odbc_fetch_into($result, $rs);
}
else
{
odbc_fetch_into($result, $rs, $rownumber);
}
}
else
{
odbc_fetch_into($result, $rownumber, $rs);
}
$rs_assoc = Array();
foreach ($rs as $key => $value)
{
$rs_assoc[odbc_field_name($result, $key+1)] = $value;
}
return $rs_assoc;
}
}
?>
</body>
</html>
And another file, query.
php that is supposed to print the data from the database:
- PHP: Select all
<html>
<body>
<?php
require_once('odbc.php');
$query = odbc_exec($odbc, "SELECT * FROM Customers") or die (odbc_errormsg());
while($row = odbc_fetch_array($query))
{
echo 'Customer First Name: '.$row['customer_first_name'].'<br />';
echo 'Customer Last Name: '.$row['customer_last_name'].'<br />';
echo 'Customer Email: '.$row['email_address'].'<br />';
echo '<hr />';
}
odbc_close($odbc);
?>
</body>
</html>
Unfortunately it just gives me a blank page! Help!
