I am going to discuss about how to read a file in Ruby

Initially we need a text file,
 
lets' start

fname = ARGV.first  #assigns file name dynamically
 text= open(fname)
print text.read  #reads the file


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 
      
    }

?>





I explain about drag and drop in JavasScript,
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
#target
{
margin-top:40px;
margin-left:600px;
width:200px;
height:200px;
border:1px solid #999;

}
</style>

</head>

<body>
<div id="target" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
<img src="img/download.jpg" width="170px" height="170x" id="dragItem" draggable="true" ondragstart="drag(event)"/>

<scrript>
function drag(a)
{
a.dataTransfer.setData("Text",a.target.id);
}
function allowDrop(a)
{
a.preventDefault();
}
function drop(a)
{
a.preventDefault();
dragItem=a.dataTransfer.getData("Text");
a.target.appendChild(document.getElementById('dragItem'));
}



</script>
</body>
</html>

Today I'm going to explain about how to connect to database using PHP and how to create databases etc

First connect to localhost
mysql_connect("localhost","username","password") or die(mysql_error());
second:create a database
$query=mysql_query("CREATE DATABASE databasename");
if($query)
{
echo "database created";
}
else
{
die(mysql_error());
}
Now we can create table under database

$query1=mysql_query("CREATE TABLE tablename(column_name datatype definition1 definition2,column_name datatype definition1 definition2");
if($query1)
{

echo "table createed";

}
else
{
die(mysql_error());
}

SQL stands for Structured Query Language ,it is used to communicate with database.According to ANSI it is the standard language for relational database  management systems.Some relational database management systems that used SQL  are MySQL ,ORACLE,Sybase etc.The standard SQL commands "SELECT","CREATE","UPDATE","DELETE" are  used by the most of the database systems .

  • SQL can create stored procedures in a database.
  • can create views in database.
SQL Statements:

  • Select is used for to select total data from the table.
  • Create is used for to create database/tables.
  • Insert into is used for to insert the data into tables.
  • Update is used for to update the data in a database.
  • Delete is used for to delete the data in a database.
  • Alter is used for to modify the database/table.
  • Drop is used for to delete  a table
SELECT:
The most commonly used SQL command is select.It is used for to retrieve the data from a table in database.
Syntax:

->"select column_list from table_name";
  • table_name is name of the table from which table you want to retrieve the data.
  • In column_list place we should write column names.
  • we can write many column names in column_list place.
->"select * from table_name";
  • using above query we can retrieve all records from table in a database
database table employ;
idfirst_namelast_nameageQualificationCompany
100chandrasekhar20B.TechCgi
101rajurajendra30B.ScTCS
102harireddy32B.EWIPRO
103Shekarkammula25MCAGoogle
104Priyaaanand45MBAhcl
example:
"select first_name from employ";
output:
first_name
chandra
raju
hari
Shekar
Priya
  • SQL is non case sensitive so we can write small or capital letters.

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