Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
PHP SQL Die 
 

PHP SQL Die results when there is a connection failure. The die( ) function prints a message and exists from the current script.

 

PHP SQL Die

                         

PHP SQL Die results when there is a connection failure. The die( ) function prints a message and exists from the current script.

Understand with Example

The Tutorial illustrate an example from 'PHP SQL Die'. To understand and grasp the example we create a table 'stu' that has required fieldnames and datatypes respectively. 

 

 

 

 

Create table Stu:

CREATE TABLE `stu` (                     
          `id` int(11) NOT NULL ,  
          `name` varbinary(10) default NULL,     
          `class` int(11) default NULL,          
          PRIMARY KEY  (`id`)                    
        );

Insert data into Stu:

The insert into is used to add the records or rows to the table 'Stu'.

INSERT INTO `stu` VALUES (1,'Ajay',12);
INSERT INTO `stu` VALUES (2,'Bhanu',12);
INSERT INTO `stu` VALUES (3,'Komal',12);
INSERT INTO `stu` VALUES (4,'Rakesh',12);
INSERT INTO `stu` VALUES (5,'Santosh',12);
INSERT INTO `stu` VALUES (6,'Tanuj',12);

php_sql_group_by.php:

The PHP code include server side scripting that include the host, user, password and database. The mysql_connect accept the host, user and password that result in the connection between the database and PHP on the server side. The Mysql php die function prints a user defined message when there is a connection failure. The die ( ) prints a message and exists from the current page.

<html>
<body>
<?php
$host = "localhost";
$user = "root";
$password = "root";
$database = "komal";
$connection = mysql_connect($host,$user,$password) 
	or die("Could not connect: ".mysql_error());
mysql_select_db($database,$connection) 
	or die("Error in selecting the database:".mysql_error());
$sql="Select * from stu";
$sql_result=mysql_query($sql,$connection) 
	or exit("Sql Error".mysql_error());
$sql_num=mysql_num_rows($sql_result);
echo "<table width =\"20%\" bgcolor=\"#F5F5FF\">";
echo "<tr>";
echo "<td ><b>Id</b></td> <td><b>Name</b>
	</td> <td><b>Class</b></td>";
echo "</tr>";
while($sql_row=mysql_fetch_array($sql_result))
{
	$id=$sql_row["id"];
	$name=$sql_row["name"];
	$class=$sql_row["class"];
	echo "<tr><td>".$id."</td>";
	echo "<td>".$name."</td>";
	echo "<td>".$class."</td></tr>";
}	
echo "</table>"
?>
</body>
</html>

Result

Id Name Class
1 Ajay 12
2 Bhanu 12
3 Komal 12
4 Rakesh 12
5 Santosh 12
6 Tanuj 12

                         

» View all related tutorials
Related Tags: sql mysql c string sed char return character cte to e use from left in m tr s urn rac

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.