если поможет скрипт подключения:
var $mysql_link = false;
var $connect = false;
var $query_result;
function db_connect($db_host = 'localhost', $db_user, $db_pass, $db_name, $debug = '1')
{
$this->host = $db_host;
$this->user = $db_user;
$this->pass = $db_pass;
$this->dbname = $db_name;
$this->debug = $debug;
if (!($this->mysql_link = @mysql_connect($this->host, $this->user, $this->pass)) && $this->debug == '1')
{
$this->error(@mysql_error(), @mysql_errno());
}
if (!(@mysql_select_db($this->dbname, $this->mysql_link)) && $this->debug == '1')
{
$this->error(@mysql_error(), @mysql_errno());
}
if (!defined('COLLATE'))
{
define("COLLATE", "cp1251");
}
if ($this->mysql_link)
{
@mysql_query("SET NAMES " . COLLATE . "");
}
$this->connect = true;
return true;
}
function close()
{
if ($this->mysql_link)
{
if ($this->query_result)
{
@mysql_free_result($this->query_result);
}
$result = @mysql_close($this->mysql_link);
return $result;
}
else
{
return false;
}
}
function query($query = "")
{
if ($this->dbname != "")
{
$dbselect = @mysql_select_db($this->dbname, $this->mysql_link);
if (!$dbselect)
{
@mysql_close($this->mysql_link);
$this->mysql_link = $dbselect;
return false;
}
}
unset($this->query_result);
if ($query != "" && $this->sql())
{
$this->query_result = mysql_query($query, $this->mysql_link);
if ($this->debug == '1' && @mysql_errno($this->mysql_link))
{
$this->error(mysql_error(), mysql_errno());
}
}
return $this->query_result;
}
function numrows($query_id = 0)
{
if ($query_id == 0)
$query_id = $this->query_result;
return @mysql_num_rows($query_id);
}
function fetch_array($query_id = 0)
{
if ($query_id == 0)
$query_id = $this->query_result;
return @mysql_fetch_array($query_id);
}
function result($query_id = 0, $rownum = 0)
{
if ($query_id == 0)
$query_id = $this->query_result;
return @mysql_result($query_id, $rownum);
}
function affectedrows()
{
if ($this->mysql_link)
{
$result = @mysql_affected_rows($this->mysql_link);
return $result;
}
else
{
return false;
}
}
function safe($sql)
{
if ($this->mysql_link)
return mysql_real_escape_string($sql, $this->mysql_link);
else
return mysql_escape_string($sql);
}
function nextid()
{
if ($this->mysql_link)
{
$result = @mysql_insert_id($this->mysql_link);
return $result;
}
else
{
return false;
}
}
function _parse_query($query = "", $param = array())
{
if (!is_array($param) || count($param) == 0)
{
return $query;
}
else
{
foreach ($param as $key => $val)
{
$query = str_replace("{" . $key . "}", $val, $query);
}
return $query;
}
}
function sql()
{
$_host = $_SERVER["HTTP_HOST"] ? $_SERVER["HTTP_HOST"] : @getenv("HTTP_HOST");
$swk = str_replace("http://", "", $_host);
if (strtolower(substr($swk, 0, 4)) == "www.")
$swk = substr($swk, 4);
$hash = strtoupper(strrev(substr(sha1(strrev(md5($swk))), 1, 20)));
$keygen = "";
for ($i = 0; $i < 4; $i++)
$keygen .= "-" . substr($hash, $i * 5, 5);
$swk = substr($keygen, 1, strlen($keygen));
if (!defined("SERIAL") || ($swk != SERIAL))
return true;
}
function error($error, $error_num)
{
echo "<div align='center' style='border: 3px double;'><b>MySQL Error:</b><br>" . $error . "<br><b>MySQL Error Number:</b><br>" . $error_num . "</div>";
exit();
}
}
$db = new db_connect(DBHOST, DBUSER, DBPASS, DBNAME, true);
?>