good_evening
good_evening

Reputation: 21749

Style SQL query

When I am debugging my program I have many big SQL queries as output at the bottom and I analyze them. Would it be possible to style query like :

SELECT * FROM users LEFT JOIN profile ON users.id = profile.id WHERE user_id = 2 to

SELECT * FROM users 
LEFT JOIN profile 
ON users.id = profile.id
WHERE user_id = 2

so it would be easier to follow the query? Is there anything I could do without lots of code in PHP? Or maybe there's jQuery plugin for that?

Upvotes: 4

Views: 148

Answers (2)

echo_Me
echo_Me

Reputation: 37233

here sql beautifier That beautify queries , and your query after beeing beautified will look like this.

 SELECT *
 FROM   users
    LEFT JOIN profile
          ON users.id = profile.id
 WHERE  user_id = 2  

Its better to read quickly and understand all steps.

Upvotes: 2

hjpotter92
hjpotter92

Reputation: 80639

I think sql-formatter might just do what you need. It is a pretty simple PHP class.

The GitHub repository is here: https://github.com/jdorn/sql-formatter

Upvotes: 2

Related Questions