search
HomePHP LibrariesOther librariesPHP library for formatting SQL statements
PHP library for formatting SQL statements
<?php
if(php_sapi_name() !== "cli") {
echo "<p>Run this php script from the command line to see CLI syntax highlighting and formatting.  It support Unix pipes or command line argument style.</p>";
echo "<pre><code>php examples/cli.php \"SELECT * FROM MyTable WHERE (id>5 AND \`name\` LIKE \&quot;testing\&quot;);\"</code></pre>";
echo "<pre><code>echo \"SELECT * FROM MyTable WHERE (id>5 AND \`name\` LIKE \&quot;testing\&quot;);\" | php examples/cli.php</code></pre>";
}
if(isset($argv[1])) {
$sql = $argv[1];
}
else {
$sql = stream_get_contents(fopen("php://stdin", "r"));
}
require_once(__DIR__.'/../lib/SqlFormatter.php');
echo SqlFormatter::format($sql);

Simply put, formatting is to initialize the disk so that we can record data on the disk step by step. For example, if we have a big house to store books, we will not move the books in and throw them on the floor. Instead, we will first set up bookshelves inside, mark them with categories, and put the books in categories.

Structured Query Language (Structured Query Language), referred to as SQL, is a database query and programming language used to access data and query, update and manage relational database systems;

sql statement is a language used to operate the database.


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

Explanation of id=%d for SQL query statements in PHPExplanation of id=%d for SQL query statements in PHP

22Dec2016

Many friends don’t know the meaning of id=%d in SQL query statement in PHP. Today, through this article, I will give you a detailed explanation of id=%d in SQL query statement in PHP. Friends who need it can refer to it.

How to write SQL statements for paging queries using PHPHow to write SQL statements for paging queries using PHP

03Apr2023

With the popularity of Web applications, many websites require paging query functions. PHP is a very popular web development language, and its built-in database access functions are also very powerful. This article will introduce how to use PHP to write SQL statements for paging queries. 1. What is paging query? Paging query refers to displaying a query result in pages, with only a fixed number of records displayed on each page. Generally speaking, paging query requires the following parameters: - The number of records displayed on each page - The page number to be displayed - The total number of records Through these parameters, we can calculate the current page that needs to be displayed

How to Optimize PHP Prepared Statements for SQL Injection Avoidance?How to Optimize PHP Prepared Statements for SQL Injection Avoidance?

21Oct2024

This article presents best practices for optimizing PHP prepared statements to prevent SQL injections. It emphasizes the crucial steps of error checking, binding parameters correctly, avoiding manual escaping, and setting parameters after binding. Ad

SQL language programming learning implementation code for escaping mysql statements in phpSQL language programming learning implementation code for escaping mysql statements in php

29Jul2016

SQL language programming learning: SQL language programming learning implementation code for escaping mysql statements in PHP: It is impossible for you to manually escape every such special character, not to mention that you usually deal with the content that is automatically submitted by the form. Therefore, the mysql_real_escape_string function should be used: mysql_real_escape_string — Escapes special characters in strings used in SQL statements, taking into account the current character set of the connection. But note: this function does not escape % and _. In addition, it is best not to use this function for the entire sql statement, but only to escape the string passed into the sql statement.

How Do I Link Static Libraries That Depend on Other Static Libraries?How Do I Link Static Libraries That Depend on Other Static Libraries?

13Dec2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

Detailed explanation of the steps for php to parse xml and generate sql statementsDetailed explanation of the steps for php to parse xml and generate sql statements

19May2018

This time I will bring you a detailed explanation of the steps for php to parse xml and generate sql statements. What are the precautions for php to parse xml and generate sql statements? The following is a practical case, let's take a look.

See all articles