PHP cant connect to MySQL

前端 未结 5 2006
我寻月下人不归
我寻月下人不归 2021-01-24 21:42
$link = mysql_connect(\'localhost\', $username, $password);
if (!$link) 
{
     die(\'Could not connect: \' . mysql_error());
}

I get this error:

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 22:03

    $username="root";
    $password="root";
    $database="test";
    
        function Save($name)
        {
            global $username;
            global $password;
            global $database;
    
            $link = mysql_connect('localhost', $username, $password);
            if (!$link) {
                die('Could not connect: ' . mysql_error());
            }
            @mysql_select_db($database) or die( "Unable to select database");
            $query = "INSERT INTO test (name)" .
                     "VALUES ('" . $name . "')";
            mysql_query($query);
            mysql_close();
        }
    

提交回复
热议问题