What Is A Database
What Is A Database
RDBMS Terminology
Column − One column (data element) contains data of one and the same
kind, for example the column postcode.
Primary Key − A primary key is unique. A key value can not occur
twice in one table. With a key, you can only find one row.
Foreign Key − A foreign key is the linking pin between two tables.
Compound Key − A compound key (composite key) is a key that
consists of multiple columns, because one column is not sufficiently
unique.
MySQL Database
MySQL is a fast, easy-to-use RDBMS being used for many small and big
businesses. MySQL is developed, marketed and supported by MySQL AB,
which is a Swedish company. MySQL is becoming so popular because of many
good reasons −
PHP mysqli_connect()
Syntax
PHP mysqli_close()
Syntax
--------------------------------------------------------------
<?php
$host ="localhost";
$user ="";
$pass ="";
if(! $conn)
mysqli_close($conn);
?>
------------------------------------------------------------------------
<?php
$sn="localhost";
$us="root";
$pa="";
$database="bit2";
$connection=new mysqli($sn,$us,$pa);
if($connection->connect_errno !=0)
die("Connection Failed:");
if($connection->query($sql))
{
else
echo "Error".$connection->error;
$connection->select_db($database);
$connection->close();
?>
<?php
$sn="localhost";
$us="root";
$pa="";
$database="bit2";
$connection=new mysqli($sn,$us,$pa,$database);
if($connection->connect_errno !=0)
die("Connection Failed:");
if($connection->query($sql))
{
echo "Table created sucessfully";
else
echo "Error".$connection->error;
?>
----------------------------------------------------------------------------------
<?php
$sn="localhost";
$us="root";
$pa="";
$database="bit2";
$connection=new mysqli($sn,$us,$pa,$database);
if($connection->connect_errno !=0)
die("Connection Failed:");
if($connection->query($sql))
else
echo "Error".$connection->error;
?>
-----------------------------------------------------------------------------------------
<?php
$sn="localhost";
$us="root";
$pa="";
$database="bit2";
$connection=new mysqli($sn,$us,$pa,$database);
if($connection->connect_errno !=0)
die("Connection Failed:");
$result=$connection->query($sql);
if($result->num_rows>0)
$row=$result->fetch_assoc();
print_r($row);
?>
<?php
$sn="localhost";
$us="root";
$pa="";
$database="bit2";
$connection=new mysqli($sn,$us,$pa,$database);
if($connection->connect_errno !=0)
die("Connection Failed:");
$result=$connection->query($sql);
?>
<?php
$sn="localhost";
$us="root";
$pa="";
$database="bit2";
$connection=new mysqli($sn,$us,$pa,$database);
if($connection->connect_errno !=0)
die("Connection Failed:");
$result=$connection->query($sql);
?>
All the settings related to register global variables, upload maximum size,
display log errors, resource limits, the maximum time to execute a PHP script
and others are written in a file as a set of directives which helps in declaring
changes.
We can execute SQL SELECT command to take a backup of any table. To take
a complete database dump we will need to write separate query for separate
table. Each table will be stored into separate text file.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = ‘';
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$table_name = "employee";
$backup_file = "/tmp/employee.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM
$table_name";
mysql_select_db('test_db');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not take data backup: ' . mysql_error());
}
mysql_close($conn);
?>