Tag Archives: MySQL

SQL

SQL referred to as Structured Query Language) is a special-purpose programming language designed for managing data in relational database management systems (RDBMS).
Originally based upon relational algebra and tuple relational calculus its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).

The query and update commands form the DML part of SQL:

SELECT – extracts data from a database
UPDATE – updates data in a database
DELETE – deletes data from a database
INSERT INTO – inserts new data into a database

The DDL part of SQL permits database tables to be created or deleted. It also defines indexes (keys), specifies links between tables, and imposes constraints between tables. The most important DDL statements in SQL are:

CREATE DATABASE – creates a new database
ALTER DATABASE – modifies a database
CREATE TABLE – creates a new table
ALTER TABLE – modifies a table
DROP TABLE – deletes a table
CREATE INDEX – creates an index (search key)
DROP INDEX – deletes an index

MySQL

MySQL is a relational database management system (RDBMS)that runs as a server providing multi-user access to a number of databases. It is named after co-founder Michael Widenius’ daughter, My. The SQL phrase stands for Structured Query Language.
The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.
Free-software-open source projects that require a full-featured database management system often use MySQL. For commercial use, several paid editions are available, and offer additional functionality.

mysql_unbuffered_query()

It executes a query on a MySQL database and buffering the result

A. Return the first data faster
B. Does not return all data faster
C. Use less memory

Example

<?php
 mysql_pconnect("localhost", "root", "phpcode") or die(mysql_error());
 $db_selected = mysql_select_db("database_name");
 echo mysql_result(mysql_unbuffered_query( "SELECT * FROM users"),1);
 mysql_close();
 ?>

mysql_tablename()

Its deprecated . It returns the table name of field

Example

<?php
mysql_connect(“localhost”, “root”, “phpcode”);
$tables = mysql_list_tables(“database_name”);
for ($i = 0; $i < mysql_num_rows($tables); $i++)
echo mysql_tablename($tables, $i), “<br />”;
?>

Output

Uusers

mysql_stat()

It  the current system status of the MySQL server

Example

<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_stat();
mysql_close();
?>

Output

Uptime: 18520 Threads: 7 Questions: 3591 Slow queries: 2 Opens: 21411 Flush tables: 1 Open tables: 63 Queries per second avg: 0.193

mysql_select_db()

It select a MySQL database

MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | ASP  |
|  3 | JSP  |
|  4 | JS  |
|  5 | AS  |
+—-+——+

Example

<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
mysql_select_db(“database_name”);
echo mysql_result(mysql_query( “SELECT * FROM users”),1);
mysql_close();
?>

Output

2

mysql_result()

It returns the value of a field in a recordset

MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | ASP  |
|  3 | JSP  |
|  4 | JS  |
|  5 | AS  |
+—-+——+

Example

<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_result(mysql_query( “SELECT * FROM users”),1);
mysql_close();
?>

Output

2

mysql_real_escape_string()

Escapes a string for use in SQL statements

MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | ASP  |
|  3 | JSP  |
|  4 | JS  |
|  5 | AS  |
+—-+——+

Example
<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_num_rows(mysql_query( “SELECT * FROM users WHERE name='”.mysql_real_escape_string(“PHP”).”‘”));
mysql_close();
?>

Output
1