connect.php中的PHP错误

时间:2014-12-09 06:39:34

标签: php connect dbconnection

我收到以下错误。我有复制粘贴代码。我对PHP知之甚少,请指导我。

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/test_bader/public_html/include/connect.php on line 66

<?php
$DBHOST = "localhost";
$DBUSER = "tese_test";
$DBPASS = "";
$DB     = "test_bader";
$default_dbname="test_bader";
*/
$DBHOST = "localhost";$
$Port= "3306";
$DBUSER = "test_test";
$DBPASS = "test@.";
$DB     = "test_bader";
$default_dbname="test_bader";


$con=mysql_connect($DBHOST,$DBUSER,$DBPASS) or die(mysql_error());
mysql_select_db($DB);

function db_connect()
{
    global $DBHOST, $DBUSER, $DBPASS, $default_dbname, $DB , $MYSQL_ERRNO, $MYSQL_ERROR;

    $link_id = mysql_connect("$DBHOST","$DBUSER","$DBPASS");
    if (!$link_id)
    {
        $MYSQL_ERRNO = 0;
        $MYSQL_ERROR = "Connection Fail to the host $DBHOST.";
    }
    else if(empty($DB ) && !mysql_select_db($default_dbname))
    {
        $MYSQL_ERRNO = mysql_errno();
        $MYSQL_ERROR = mysql_error();
        return 0;
    }
    else if(!empty($DB ) && !mysql_select_db($DB ))
    {
        $MYSQL_ERRNO = mysql_errno();
        $MYSQL_ERROR = mysql_error();
        return 0;
    }
    else return $link_id;
}




function sql_error()
{
    global $MYSQL_ERRNO, $MYSQL_ERROR;
    if(empty($MYSQL_ERROR))
    {
        $MYSQL_ERRNO = mysql_erron();
        $MYSQL_ERROR = mysql_error();
    }
    return "$MYSQL_ERRNO : $MYSQL_ERROR";
}

function q($st)
{
    $r=mysql_query($st);
    return $r;
}
function f($st)
{
    $r=mysql_fetch_array($st);
    return $r;
}

?>

1 个答案:

答案 0 :(得分:-1)

<?php
$DBHOST = "localhost";
$DBUSER = "tese_test";
$DBPASS = "";
$DB     = "test_bader";
$default_dbname="test_bader";
*/
$DBHOST = "localhost";$
$Port= "3306";
$DBUSER = "test_test";
$DBPASS = "test@.";
$DB     = "test_bader";
$default_dbname="test_bader";


$con=mysql_connect($DBHOST,$DBUSER,$DBPASS) or die(mysql_error());
mysql_select_db($DB);

function db_connect()
{
	global $DBHOST, $DBUSER, $DBPASS, $default_dbname, $DB , $MYSQL_ERRNO, $MYSQL_ERROR;
	
	$link_id = mysql_connect("$DBHOST","$DBUSER","$DBPASS");
	if (!$link_id)
	{
		$MYSQL_ERRNO = 0;
		$MYSQL_ERROR = "Connection Fail to the host $DBHOST.";
	}
	else if(empty($DB ) && !mysql_select_db($default_dbname))
	{
		$MYSQL_ERRNO = mysql_errno();
		$MYSQL_ERROR = mysql_error();
		return 0;
	}
	else if(!empty($DB ) && !mysql_select_db($DB ))
	{
		$MYSQL_ERRNO = mysql_errno();
		$MYSQL_ERROR = mysql_error();
		return 0;
	}
	else return $link_id;
}




function sql_error()
{
	global $MYSQL_ERRNO, $MYSQL_ERROR;
	if(empty($MYSQL_ERROR))
	{
		$MYSQL_ERRNO = mysql_erron();
		$MYSQL_ERROR = mysql_error();
	}
	return "$MYSQL_ERRNO : $MYSQL_ERROR";
}

function q($st)
{
	$r=mysql_query($st);
	return $r;
}
function f($st)
{
	$r=mysql_fetch_array($st);
	return $r;
}

?>