The SQL SELECT order is utilized to bring information from the MySQL data set. You can utilize this order at mysql> speedy as well as in any content like PHP.
Linguistic structure
Here is conventional SQL linguistic structure of SELECT order to get information from the MySQL table
SELECT field1, field2,...fieldN
FROM table_name1, table_name2...
[WHERE Clause]
You can utilize at least one tables isolated by comma to incorporate different circumstances utilizing a WHERE provision, however the WHERE condition is a discretionary piece of the SELECT order.
You can bring at least one fields in a solitary SELECT order.
You can determine star (*) instead of fields. For this situation, SELECT will return every one of the fields.
You can indicate any condition utilizing the WHERE provision.
Getting Information Utilizing a PHP Content
PHP utilizes MySQL question() or mysql_query() capability to choose records from a MySQL table. This capability takes two boundaries and returns Valid on progress or Misleading on disappointment.
Sentence structure
$mysqli->query($sql,$resultmode)
Sr.No. Parameter and Portrayal
1.
$sql
Required - SQL inquiry to choose records from a MySQL table.
2. $resultmode
Discretionary - Either the consistent MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT relying upon the ideal way of behaving. As a matter of course, MYSQLI_STORE_RESULT is utilized.
Model
Attempt the accompanying guide to choose a record from a table − Reorder the accompanying model as mysql_example.php −
<html>
<head>
<title>Creating MySQL Table</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root@123';
$dbname = 'Instructional exercises';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($mysqli->connect_errno ) {
printf("Connect fizzled: %s<br/>", $mysqli->connect_error);
exit();
}
printf('Connected successfully.<br/>');
$sql = "SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl";
$result = $mysqli->query($sql);
in the event that ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
printf("Id: %s, Title: %s, Creator: %s, Date: %d <br/>",
$row["tutorial_id"],
$row["tutorial_title"],
$row["tutorial_author"],
$row["submission_date"]);
}
} else {
printf('No record found.<br/>');
}
mysqli_free_result($result);
$mysqli->close();
?>
</body>
</html>
Yield
Associated effectively.
Id: 1, Title: MySQL Instructional exercise, Creator: Mahesh, Date: 2021
Id: 2, Title: HTML Instructional exercise, Creator: Mahesh, Date: 2021
Id: 3, Title: PHP Instructional exercise, Creator: Mahesh, Date: 2021
Id: 4, Title: Java Instructional exercise, Creator: Mahesh, Date: 2021
Id: 5, Title: Apache Instructional exercise, Creator: Suresh, Date: 2021
0 Comments