use portable db with php project code example

Example 1: mysql connection phpmyadmin

<?php
  // This is for checking if your file is linked in your page or game or whatever
  echo "IT WORKS"; // My File is successfuly Linked

  //Remember to create a Database in phpmyadmin or any Online Database
  // the values passed in this parameters are:  the host, the user, user password and the database Name
  $con = mysqli_connect('localhost', 'root', 'root', 'unityaccess');

  // check that connection happen
  if(mysqli_connect_errno()) {
    echo "1: Connection Failed"; //error code #1 = connection Failed
    exit();
  }
?>

Example 2: how do you connect the database

I USE JDCB
I use CONNECTION database to make connection
I create STATEMENT than I use statement to create query 
And run the query and get the RESULT SET


Connection = import java.sql.Connection;
Driver manager = import java.sql.DriverManager;
Connection connection = DriverManager.getConnection(url, userName, passWord);

Connection String Syntax:
jdbc:DataBaseType"subprotocal:Host:port:SID

After succesfully created the connect next step is STATEMENT

import java.sql.Statement;
Statement statement = connection.createStatement();

-We use createStatement() method to create the statement from our connection.
-The result we get from this type of statement can only move from top to bottom,
not other way around

Once we have statement we can run the query and get the result to
ResultSet format 
		import java.sql.ResultSet;
        
We use the method executeQuery() to execute our queries

ResultSet result = statement.executeQuery("Select * from employees");

Tags:

Php Example