Use this for MySQL
SELECT COUNT(*) FROM table_name;
PHP is an important part of the web world, and every web developer should have the basic knowledge in PHP. Common PHP questions, which should help you become a best PHP developer.
Use this for MySQL
SELECT COUNT(*) FROM table_name;
Here is how can you find the number of rows in a result set in PHP:
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;
SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();
The generic syntax for GRANT is as following
GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all databse by using *.* or some specific database by database.* or a specific table by database.table_name.
CREATE USER ‘user01’@’localhost’ IDENTIFIED BY ‘mypass’;
GRANT ALL ON db1.* TO 'user01'@'localhost'; GRANT SELECT ON db2.invoice TO 'user01'@'localhost'; GRANT USAGE ON *.* TO 'user01'@'localhost' WITH MAX_QUERIES_PER_HOUR 90;
The generic syntax for revoke is as following
REVOKE [rights] on [database] FROM [username@hostname]
The REVOKE statement enables system administrators to revoke privileges from MySQL accounts.
Now rights can be:
a) ALL privileges
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all database by using *.* or some specific database by database.* or a specific table by database.table_name.
REVOKE INSERT ON *.* FROM 'user01'@'localhost';
CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, “Hello!” will be stored as “Hello! ” in CHAR(10) column.
VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, “Hello!” will be stored as “Hello!” in VARCHAR(10) column.
AES_ENCRYPT() and AES_DECRYPT()
string md5(string)
It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.
The MySQL provides a LOAD DATA INFILE command. You can load data from a file. Great tool but you need to make sure that:
a) Data must be delimited
b) Data fields must match table columns correctly
Use DATEDIFF()
SELECT DATEDIFF(NOW(),’2006-07-01′);