Tag: queries

MySQL, PHP

Using MySQL Prepared Statements in PHP

A good reason to use prepared statements is to avoid SQL injection without needing to escape data. Connect $conn = mysqli_connect("localhost", "user_name", "xxxxxxxx", "dbname"); if ($conn->connect_errno) { echo "Connection failed: " . $conn->connect_errno . " – " . $conn->connect_error; }$conn = mysqli_connect("localhost", "user_name", "xxxxxxxx", "dbname"); if ($conn->connect_errno) { echo "Connection failed: " . $conn->connect_errno . …

Databases, Microsoft SQL Server

Retrieve useful information from SQL Server

Today we will see how can we retrieve various information from Microsoft SQL Server using SQL queries. Get all users: SELECT * FROM sys.server_principals;SELECT * fROM sys.server_principals; Get database size: USE master GO   EXEC sp_spaceuseduse master go exec sp_spaceused Get user privilleges for current database: USE master GO   SELECT SYSOBJECTS.name AS ‘objectname’, SYSUSERS.name …

Databases, MySQL

Retrieve useful information from MySQL

Today we will see how can we retrieve various information from mysql server using SQL queries. Get all users: SELECT * FROM mysql.user;select * from mysql.user; Get top 10 tables in size: SELECT concat(table_schema,’.’,TABLE_NAME) TABLE_NAME, concat(round(data_length/(1024*1024),2),’M’) data_length FROM information_schema.TABLES ORDER BY data_length DESC LIMIT 10;SELECT concat(table_schema,’.’,table_name) table_name, concat(round(data_length/(1024*1024),2),’M’) data_length FROM information_schema.TABLES ORDER BY data_length DESC …