This tutorial is for those who want to get start with mysql and php . But have no knowledge about it . This tutorial is designed in simple and  easy way .We will provide you  step by step guide for getting started with php with mysql
  • Problems

    This line enable URL Rewriting . It must be enabled via the RewriteEngine directive! and if your .htaccess file is going to use rewrite rules, you should always include this line. Otherwise, you can’t be sure if its enabled or not. The string “on” is case insensitive.

PHP WITH MYSQL

Making connection to mysql:

1)VARIABLE TYPE
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$db_con = mysqli_connect($servername, $username, $password);

// Check connection
if (!$db_con) {
    die("Connection failed: " . mysql_error());
}
echo "Connected successfully";
?>

1)Direct Method
<?php


// Create connection
$db_con = mysqli_connect('localhost', 'username', 'password');

// Check connection
if (!$db_con) {
    die("Connection failed: " . mysql_error());
}
echo "Connected successfully";
?>

Creating database:

1)VARIABLE TYPE
<?php
$db_name = 'makeownwebsite';
$create =mysql_query("CREATE DATABASE  $db_name");
if (!create) die ("unable to create database :" . mysql_error());
  ?>

1)Direct Method
<?php
mysql_query("CREATE DATABASE makeownwebsite") or die (mysql_error());
?>

Selecting database:

1)VARIABLE TYPE
<?php
$db_name = 'makeownwebsite';
$select =mysql_select_db($db_name);
if (!select) die ("unable toselect database :" . mysql_error());
  ?>

1)Direct Method
<?php
mysql_select_db(" makeownwebsite") or die (mysql_error());
?>

No comments:

Post a Comment