dbconnect函数错误

时间:2011-12-05 20:40:09

标签: php

在我的dbconnect函数中的某个地方,它并没有在正确的位置关闭。我一遍又一遍,我仍然找不到它。 这是我的dbconnect函数:

    function dbConnect(){
     // Connect to the database:
     $hostname="localhost";
     $database="tblFile";
     $mysql_login="valerie2_shuawna";
     $mysql_password="norris";

     if(!($db=mysql_connect($hostname, $mysql_login, $mysql_password))){
        echo"error on connect";
     }
     else{
        if(!(mysql_select_db($database,$db))){
            echo mysql_error();
            echo "<br />error on database connection. Check your settings.";
        }
        else{
                    echo "I have successfully made a connection to my database and everything
     is working as it should.";
   }
}

然后这是另一个具有dbconnect()的部分:

dbConnect();
    $SQL="SELECT fileID FROM tblFile WHERE fileName='".$result."'";
    //echo $SQL;
    $rs=mysql_query($SQL);
    echo mysql_num_rows($rs);
    if(mysql_num_rows($rs)!=0){
        $extension=strrchr($result,'.');
        $result=str_replace($extension,time(),$result);
        $result=$result.$extension;
    }
    return $result;
}

我无法找到它应该在何处关闭的地方。

1 个答案:

答案 0 :(得分:0)

在代码的第一部分中,您缺少一个括号

我建议你使用这种形式的if语句

function dbConnect()
{
     // Connect to the database:
     $hostname="localhost";
     $database="tblFile";
     $mysql_login="valerie2_shuawna";
     $mysql_password="norris";

     if(!($db=mysql_connect($hostname, $mysql_login, $mysql_password))):
        echo"error on connect";
     else:
        if(!(mysql_select_db($database,$db))):
            echo mysql_error();
            echo "<br />error on database connection. Check your settings.";
        else:
            echo "I have successfully made a connection to my database and everything is working as it should.";
        endif; 
   endif; 
}

告诉我结果