Mysql Programs
Mysql Programs
<?php
$servername = "127.0.0.1";
$username = "phpwithmysql1";
$password = "123456";
// Create connection
// Check connection
if ($conn->connect_error)
// Create database
} else {
$conn->close();
?>
Output:
2.Write a PHP application to create table.
<?php
$servername = "127.0.0.1";
$username = "phpwithmysql";
$password = "123456";
$dbname = "cse";
// Create connection
// Check connection
if ($conn->connect_error) {
)";
} else {
$conn->close();
?>
<?php
$servername = "127.0.0.1";
$username = "phpwithmysql";
$password = "123456";
$dbname = "cse";
// Create connection
// Check connection
if ($conn->connect_error) {
VALUES (102,'kavitha',20000,202)";
} else {
$conn->close();
?>
Output:
4. Write a PHP application to fetch the Rows from the table.
<?php
$servername = "127.0.0.1";
$username = "phpwithmysql";
$password = "123456";
$dbname = "cse";
// Create connection
// Check connection
if ($conn->connect_error) {
$result = $conn->query($sql);
if ($result->num_rows> 0) {
while($row = $result->fetch_assoc()) {
} else {
echo "0 results";
$conn->close();
?>
<?php
$servername = "127.0.0.1";
$username = "phpwithmysql";
$password = "123456";
$dbname = "cse";
// Create connection
// Check connection
if ($conn->connect_error) {
} else {
}
$conn->close();
?>
Output:
6.Write a program to read user information like name, email from
user and display all these information on output screen.
form.html
<html>
<body bgcolor="pink">
<input type="submit">
</form>
</body>
</html>
welcome.php
<?php
$name=$_POST["name"];
$email=$_POST["email"];
// Check connection
if ($conn->connect_error) {
} else {
$result = $conn->query($sql);
if ($result->num_rows> 0) {
while($row = $result->fetch_assoc()) {
} else {
$conn->close();
?>
Output: