conn.log文件在你运行的php文件的同级

<?php
header('Content-Type:text/html;charset=utf-8');

date_default_timezone_set('Asia/Shanghai');
function makeErrorLog($filename,$errormsg) {
$fp = fopen($filename,'a');//模式是写入方式打开
$str = "错误日期:".date('Y-m-d H:i:s')."==错误内容:".$errormsg;
fwrite($fp,$str);//写入
fclose($fp);//关闭
}
$dataname = 'a';//数据库
$conn = mysql_connect('localhost','root','');//数据库软件密码账号,本地地址
if($conn){
$r =mysql_select_db($dataname,$conn);
if($r){
mysql_query('set names utf8');//指定的字符编码
}else{
makeErrorLog('conn.log',$dataname.'数据库不存在');
}
}else{
makeErrorLog('conn.log','数据库连接失败!');
}
$sql = "select * fro1m voto";//首先数据库要链接成功,sql语句错误才行哦
$result = mysql_query($sql);
$arr = mysql_fetch_assoc($result);
if($arr){
print_r($arr);
}else{
makeErrorLog('conn.log','SQL语句执行错误!');
}
?>

原生php创建错误日志文件_mysql