Reading data In MYSQL

Reading data In MYSQL Here , we will study how to read data from the database. To read the data from the database use the SELECT statement. To send SQL statements to the MySQL server, a user need to use the query method of the PDO object:

$conn- > query ( $sql );

If the SQL statement returns rows of data as a result set, a user can capture the data by assigning them result of $conn – > query to a variable:

$rows = $conn- > query ( $sql );

The result returned by $conn – > query is actually another type of object, called a PDOStatement object. You can use this object along with a foreach loop to move through all the rows in the result set. Each row is an associative array containing all the field names and values for that row in the table.


$sql = “SELECT * FROM Course”;
$rows = $conn- > query( $sql );
foreach ( $rows as $row )
echo “name = “ . $row[“Course name”] . “ < br / > ”;
echo “color = “ . $row[“Duration”] . “ < br / > ”;

Scroll to Top