<?php
function db_connect()
{
// Load SQL server variables
require("config.inc.php");
$result = mysql_pconnect($cfg['sqlserver'], $cfg['sqlusername'], $cfg['sqlpassword']);
if (!$result)
{
return false;
}
if (!mysql_select_db($cfg['sqldatabase']))
{
echo "<h4>Error: cannot connect to the database \"" . $cfg['sqldatabase'] . "\" on server \"" . $cfg['sqlserver'] . "\".<BR>";
echo_db_error();
exit;
}
return $result;
}
function echo_db_error()
{
$cfg = $GLOBALS["cfg"];
echo "<B>MySQL error " . mysql_errno() . ": " . mysql_error() . "<BR>";
echo "Please contact the database administrator, " . $cfg['adminname'] . ", at " . $cfg['adminemail'] . ".</B><P>";
}
function db_result_to_array($result)
{
$res_array = array();
for ($count=0; $row = mysql_fetch_array($result); $count++)
$res_array[$count] = $row;
return $res_array;
}
function organization_exists($orgid)
{
// Make a connection to the database
$conn = db_connect();
// Check to see if the organization with $orgid exists
$query = "select Org_ID from Organizations where Org_ID = $orgid";
$result = mysql_query($query);
if (!$result)
{
// Database error
echo "<BR>Database error:<BR>";
echo_db_error();
return 0;
}
if (mysql_num_rows($result) > 0)
{
return 1;
}
else
{
return 2;
}
}
function mysql_major_version () {
$conn = db_connect();
$longversion = mysql_get_server_info();
preg_match('/^(\d)/', $longversion, $matches);
$majorversion = $matches[1];
mysql_close($conn);
return $majorversion;
}
?>