How to use select statement in MySQL through PHP

In this article I am going to explain about how to retrieves table data from MySQL.
  • 1980

PHP MySQL select statement

The select statements is used to retrieves data from one or more tables.

Syntax of select statement

SELECT columnName FROM tableName;
or
SELECT *(for hole table) FROm tableName;

Example of  select statement

<html>

<body>

<?php

$con = mysql_connect("localhost","gupta","sharad");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("Mcn_Solution", $con);

 

$result = mysql_query("SELECT * FROM Emp");

 

while($row = mysql_fetch_array($result))

  {

  echo $row['Fname'] . " " . $row['LastName'] . " ". $row['Id'];

  echo "<br />";

  }

 

mysql_close($con);

?>

</body>

</html>


Output:

select mysql.jpg

You may also want to read these related articles :
here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.