如何将mysql php错误写入文本文件

I have the following PHP code that creates a mysql connection:

$link = mysqli_connect("$mysql_server", "$mysql_user", "$mysql_pw", "$mysql_db");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

In the event the connection is not made, how can I write the error to a text file on my server?

Yes it is possible with error_log function in php

$con = mysqli_connect("$mysql_server", "$mysql_user", "$mysql_pw", "$mysql_db");
if (!$con)
{
    error_log(mysqli_error($con) . "
", 3, "/var/tmp/my-errors.log");
}