Reputation: 17
Trying to Create a text file with MySQL database errors because I never get to see the page.
mysql_query(
"INSERT INTO cart (value1) VALUES ('value1')", $link)
or die(mysql_error());
But I want to replace the mysql_error into a text file, any thoughts?
Upvotes: 1
Views: 808
Reputation: 1
Here is a quick way to write the mysql_error() to a log file.
$file = fopen('mysql_error.log','a');
mysql_query($query)
or
die(fwrite($file1,"$query".mysql_error(). "\n"));
This will write the query and the error on the same line of the log file.
Upvotes: 0
Reputation: 3680
You can just create text file on MySQL error and log MySQL error in it.
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
$db = mysql_select_db("nonexistentdb", $link);
if(!$db) {
$err = mysql_errno($link) . ": " . mysql_error($link). "\n";
$file = fopen('filename.txt', 'a');
fwrite($file, $err);
}
Upvotes: 1
Reputation: 1755
you can put your function in die()
or die(your_function(mysql_error()))
function your_function(e){
file_put_contents('log.txt', e);
}
Upvotes: 2