Creating database and tables on terminal
first access mysql on terminal
type :mysql -u root -p
password:xxxxx
write query for creating database
mysql>CREATE DATABASE reddy;
Query OK, 1 row affected (0.02 sec)
under reddy database we r creating table ,so
mysql> use reddy;
Database changed
reddy database selected,now create table
mysql> create table bang(id int(22) AUTO_INCREMENT,name varchar(20) NOT NULL,Country varchar(20) NOT NULL,PRIMARY KEY(id));
Query OK, 0 rows affected (0.21 sec)
we created table ,if u want to check,go to localhost/phpmyadmin,u can findout ur database
if we want to see total databases
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chandu |
| hi |
| mysql |
| performance_schema |
| phpmyadmin |
| reddy |
| scsr |
| shoppingcart |
| studentjob |
| test |
+--------------------+
11 rows in set (0.00 sec)
Now I will explain about how to connect php to database
goto .php or .html page
<?php
first connect to database
$con=mysql_connect("localhost", "username of database", "password of database");
if (!$con)
{
die('Could not connect to Data base:' . mysql_error());
}
$ret=mysql_select_db("edvantedge", $con);
if (!$ret )
{
die('Error: ' . mysql_error()); //mysql_error()-if anything error occurs it displays nothing
}
we connected to database ,now we can insert,update,select tables from database
$sql="select * from tablename";
$res = mysql_query($sql,$con);
if (!$res)
{
die('Error: ' . mysql_error());
}
mysql_fetch_array-Fetch a result row as an associative array, a numeric array or both
while($row = mysql_fetch_array($res))
{
echo $row['id'] ; // if u want to get only all rows of one column in table
}
?>