MySQL: Logging SQL Statements for Debugging PHP Apps

In summary, The goal is to log SQL statements with the time they were executed. However, when trying to insert the values, MySQL syntax errors occur. The solution is to double apostrophes in the inserts.
  • #1
rdx
50
0
Goal: I seek to log the SQL statements into a MySQL table, with the time they were executed as an aid to debugging problems with PHP apps I am writing.

Problem: MySQL seems to try to interpret the statement, meant to simply be data in a field. When I try to "INSERT" the values, I get MySQL syntax errors.

Solution: Does anyone have a way around this problem?
 
Technology news on Phys.org
  • #2
Do your inserts have apostrophes? You'll need to double them (replace ' with '').
 
  • #3
verty said:
Do your inserts have apostrophes? You'll need to double them (replace ' with '').

Hmmm, I see what you mean.. I will look into it. Thanks.
 

1. What is MySQL?

MySQL is an open-source relational database management system (RDBMS) that is commonly used for web applications. It stores and manages data in a structured format, allowing for efficient querying and manipulation of data.

2. What is logging SQL statements?

Logging SQL statements involves recording the queries that are executed on a MySQL database. This can be useful for debugging purposes, as it allows developers to track the flow of data and identify any errors or issues in their code.

3. How can I enable logging of SQL statements in MySQL?

To enable logging of SQL statements in MySQL, you can modify the MySQL configuration file (my.cnf) and set the 'general_log' and 'general_log_file' parameters to 'ON' and a desired file path, respectively. This will create a log file that contains all SQL statements executed on the database.

4. Can I specify which SQL statements to log?

Yes, you can specify which SQL statements to log by using the 'log' parameter in your MySQL configuration file. This allows you to filter by specific databases, tables, or queries, which can be helpful in managing large amounts of data and avoiding unnecessary logs.

5. Why is logging SQL statements important for debugging PHP apps?

Logging SQL statements is important for debugging PHP apps because it provides developers with a comprehensive record of the queries executed on the database. This can help identify any errors or performance issues in the code, and allows for easier tracking and resolution of bugs.

Similar threads

  • Programming and Computer Science
Replies
7
Views
425
  • Programming and Computer Science
Replies
12
Views
9K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
2
Views
304
  • Programming and Computer Science
Replies
5
Views
5K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
Replies
1
Views
3K
  • Programming and Computer Science
Replies
7
Views
2K
Back
Top