1

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?

1
  • I see you're new to Stack Overflow. Be sure to give the about page a read if you haven't already, and be sure to select an answer to your question once you've found what you're looking for. Commented Dec 6, 2013 at 6:27

3 Answers 3

2

you can put your function in die()

 or die(your_function(mysql_error()))

 function your_function(e){
    file_put_contents('log.txt', e);
 }
Sign up to request clarification or add additional context in comments.

Comments

1

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);
}

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.