Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
 
 


 

PHP SQL Array

                         

PHP SQL Array is the set of collection of one or more similar variable under single name. Usually we have different type of values whose datatypes are same, Array is used as substitute for those variable, which have the same datatypes and store the data as element in array.

Understand with Example

This example illustrates how to create array in the operation of sql for php application. To start with the example, we create a emp_table with given required fieldnames and values. The Select query fetches all the records from table 'emp_table'.

Table: emp_table

 

To execute the sql query in PHP, we create sql_array.php. The sql_array.php  starts with the <?php and end with ?>, which consists of con variable. The con var is used to initialized with the mysql_connect ( ) function, which accept the parameter local host, user and password in order to authenticate the connection between the PHP and MySQL. In case the specified parameter are not valid, the con fail to establish the connection between the PHP and MySQL. Otherwise the connection bridge is  built successfully between the PHP and MySQL. In this example we create a $emp_name[] and $emp_designation[] of array type. In this array type variable we put the value of row[0] and row[1] which fetched records from database table. The echo print the record details of table 'emp_table' whose emp_id is "1" in the HTML table.

Source Code of sql_array.php 

<?php
  $con = mysql_connect("localhost","root","root");
  if (!$con){
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test", $con);

  $sql = "SELECT emp_name, emp_designation FROM emp_table WHERE emp_id=1";

  $result = mysql_query($sql, $con);

  while($row=mysql_fetch_row($result)){
    echo $emp_name[] = $row[0" || ";
    echo $emp_designation[] = $row[1];
  }
  mysql_free_result($result);

  mysql_close($con);
?>

Download Source Code

Output:

                         

» View all related tutorials
Related Tags: sql mysql c com table comparison sed char command vi operator pattern return opera character tab like for ie record

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.