---
title: "Selecting record from MySQL database in PHP"  
description: "‘Select’ statement is used to select record from MySQL database server.Synatx: select column_name  from  table_nameLet’s have an example, how to selec"  
author: "Anonymous User"  
published: 2011-09-20  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/735/selecting-record-from-mysql-database-in-php  
category: "php"  
tags: ["php"]  
reading_time: 2 minutes  

---

# Selecting record from MySQL database in PHP

‘Select’ statement is used to select record from [MySQL database](https://www.mindstick.com/forum/390/how-to-create-mysql-database-backup-file-using-php) [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over).Synatx: select column_name from table_name

Let’s have an example, how to select record from MySQL database server.

##### Example:

```
<?php    //  creatingconnection with mysql database server      $con = mysql_connect("localhost", "root", "root");    // check connection is establish or not    if(!$con)    {        die ("Connectionnot established!  Please try again");    }      echo '<b>Connection successfully open</b>'.'</br>';    // selecting database      mysql_select_db("MySqlDatabase", $con);    //  selectingrecord    $qry = "Select * from mysqldatabse.tbllogin";      //  printselecting record    $qryResult= mysql_query($qry);       while ($row =  mysql_fetch_array($qryResult))    {         echo $row['Name'].'   '.$row['EmailId'].'   '.$row['Password'];         echo '</br>';    }      //  Closingthe connection       mysql_close($con);     echo '<b>Connection closed successfully</b>';?>
```

## \

**Note:** mysql_query() [function](https://www.mindstick.com/articles/43970/purchase-suitable-wedding-dresses-for-your-wedding-function) sends a [unique](https://yourviews.mindstick.com/view/81599/how-to-change-yourself-follow-these-4-unique-life-hacks-for-good) query ([multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) [queries](https://www.mindstick.com/forum/161063/how-to-optimize-entity-framework-core-queries-for-large-datasets) are not supported) to the currently [active](https://answers.mindstick.com/qa/97113/why-does-an-active-ftp-not-work-with-network-firewalls) database on the server that's associated with the specified link_identifier and mysql_fetch_array()function returns an array that corresponds to the fetched row and moves the [internal](https://www.mindstick.com/interview/773/describe-the-accessibility-modifier-protected-internal) data [pointer](https://www.mindstick.com/articles/11/pointers) ahead.

##### Output:

![Selecting record from MySQL database in PHP](https://www.mindstick.com/mindstickarticle/066b6c08-ac07-4a1a-852e-bc8d1195af60/images/fa6dc61b-d4b4-4a80-92af-95e838cf163d.png)

##### Note: ‘*’ is used for selecting all records from table.

You can select specific column record.

```
<?php    //  creatingconnection with mysql database server      $con = mysql_connect("localhost", "root", "root");    // check connection is establish or not    if(!$con)    {        die ("Connectionnot established!  Please try again");    }      echo '<b>Connection successfully open</b>'.'</br>';    // selecting database      mysql_select_db("MySqlDatabase", $con);    //  selectingrecord with specified column name    $qry = "Select Name,EmailId,Password from mysqldatabse.tbllogin";      $qryResult= mysql_query($qry);    //  printselecting record     while ($row =  mysql_fetch_array($qryResult))    {         print_r($row);         echo '</br>';    }    //Closingthe connection     mysql_close($con);     echo '<b>Connection closed successfully</b>';?>
```

**Note:** print_r() function is used for print array.

##### Output:

![Selecting record from MySQL database in PHP](https://www.mindstick.com/mindstickarticle/066b6c08-ac07-4a1a-852e-bc8d1195af60/images/58c4f74d-9f1f-447c-b872-37022bde6791.png)

##### Example: Selecting record with ‘where’ clause

```
<?php    //  creatingconnection with mysql database server      $con = mysql_connect("localhost", "root", "root");    // check connection is establish or not    if(!$con)    {        die ("Connectionnot established!  Please try again");    }      echo '<b>Connection successfully open</b>'.'</br>';    // selecting database      mysql_select_db("MySqlDatabase", $con);    //  selectingrecord with where clause    $qry = "Select Password from mysqldatabse.tbllogin where EmailId ='arunsingh@yahoomail.com'";      $qryResult= mysql_query($qry);    //  printselecting record     while ($row =  mysql_fetch_array($qryResult))    {        echo 'Password is : '.$row['Password'];         echo '</br>';    }    //Closingthe connection     mysql_close($con);     echo '<b>Connection closed successfully</b>';?>
```

##### Output:

![Selecting record from MySQL database in PHP](https://www.mindstick.com/mindstickarticle/066b6c08-ac07-4a1a-852e-bc8d1195af60/images/294d586b-c06b-400c-9d50-f3015e17a5ae.png)

\

---

Original Source: https://www.mindstick.com/articles/735/selecting-record-from-mysql-database-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
