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 
      
    }

?>





0 comments:

Popular Posts

Blogger templates

Blogger news

Blogroll

Navigation

Total Pageviews

Powered by Blogger.

Labels

About Me hi this is chandrasekhar completed B.Tech in 2012.I like blogging

Labels

Labels

Blogroll

Featured Post (Slider)

About

Contact us

Combine

Horizontal

Vertical1

Gallery

Vertical2

Portfolio

Contact Form

Name

Email *

Message *

Most Trending

Top 10 Articles