user3014203
user3014203

Reputation: 17

PHP - Create Text file on mysql Error

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

Answers (3)

DJ_007
DJ_007

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

sravis
sravis

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

mehdi
mehdi

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

Related Questions