1<?php
2$servername = "localhost";
3$username = "username";
4$password = "password";
5$dbname = "myDB";
6
7// Create connection
8$conn= mysqli_connect($servername,$username,$password,$dbname);
9// Check connection
10if (!$conn) {
11 die("Connection failed: " . mysqli_connect_error());
12}
13echo "Connected Successfully.";
14?>
1$servername = "localhost";
2$username = "username";
3$password = "password";
4
5// Create connection
6$conn = new mysqli($servername, $username, $password);
7
8// Check connection
9if ($conn->connect_error) {
10 die("Connection failed: " . $conn->connect_error);
11}
12echo "Connected successfully";
13
14
15Simplified
16
17$conn = mysqli_connect('localhost', 'username', 'password');
18$database = mysqli_select_db($conn, 'database');
1I USE JDCB
2I use CONNECTION database to make connection
3I create STATEMENT than I use statement to create query
4And run the query and get the RESULT SET
5
6
7Connection = import java.sql.Connection;
8Driver manager = import java.sql.DriverManager;
9Connection connection = DriverManager.getConnection(url, userName, passWord);
10
11Connection String Syntax:
12jdbc:DataBaseType"subprotocal:Host:port:SID
13
14After succesfully created the connect next step is STATEMENT
15
16import java.sql.Statement;
17Statement statement = connection.createStatement();
18
19-We use createStatement() method to create the statement from our connection.
20-The result we get from this type of statement can only move from top to bottom,
21not other way around
22
23Once we have statement we can run the query and get the result to
24ResultSet format
25 import java.sql.ResultSet;
26
27We use the method executeQuery() to execute our queries
28
29ResultSet result = statement.executeQuery("Select * from employees");
1Connection =
2 Helps our java project connect to database
3Statement =
4 Helps to write and execute SQL query
5ResultSet =
6 A DataStructure where the data from query result stored
7+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
9
10 After succesfully created the connect
11next step is STATEMENT
12
13Statement statement = connection.createStatement();
14We use createStatement() method to create
15the statement from our connection.
16-The result we get from this type of statement
17can only move from top to bottom,
18not other way around
19
20Statement statement = connection.
21createStatement(ResultSet TYPE_SCROLL_INSENSITIVE
22,ResultSet CONCUR_READ_ONLY);
23
24-The result we get from this type of
25statement can freely move between rows
26
27Once we have statement we can run
28the query and get the result to
29ResultSet format
30 import java.sql.ResultSet;
31
32We use the method executeQuery()
33to execute our queries
34
35ResultSet result = statement.
36 executeQuery("Select * from employees");