我收到警告:fwrite()期望参数1是资源,给定null

So I am getting this warning and I cannot figure out what is wrong with the code. The section of code that its pointing to is shown below.

ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);

$adconn = ldap_connect("ldap://earth.matcor-matsu.com") or die("Couldn't connect to AD!");

//------1
if($adconn){
    echo fwrite($log,'$adconn : ' . $adconn. "
");
    echo fwrite($log,"
");
}else{
    echo 'Unable to connect to LDAP server';
}

$log needs to be set with a fopen('data.txt', 'w') (example). You need to tell the PHP what the file handle actually is.

http://php.net/manual/en/function.fwrite.php

before the if statement also output by writing:

var_dump($log) to check you've got a valid value of $log - as in not NULL