Skip to content

Instantly share code, notes, and snippets.

@Shakil-Shahadat
Last active December 18, 2021 01:46
Show Gist options
  • Save Shakil-Shahadat/aa94fb3701ef52b54e2f8aedbbc994c5 to your computer and use it in GitHub Desktop.
Save Shakil-Shahadat/aa94fb3701ef52b54e2f8aedbbc994c5 to your computer and use it in GitHub Desktop.
Create Database
<?php
require_once 'db_info.inc';
$db = new mysqli( $servername, $username, $password );
if ( $db->connect_error ) die( 'Connection Error: ' . $db->connect_error );
$result = $db->query( "CREATE DATABASE IF NOT EXISTS $database" );
if ( $db->error ) die( 'Query Error: ' . $db->error );
else echo 'Database creation successful.';
<?php
require_once 'db_connect.inc';
$result = $db->query( '' );
if ( $db->error ) die( 'Query Error: ' . $db->error );
else echo 'Table creation successful.';
<?php
require_once 'db_info.inc';
$db = new mysqli( $servername, $username, $password, $database );
if ( $db->connect_error ) die( 'Connection Error: ' . $db->connect_error );
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$database = '';
@Shakil-Shahadat
Copy link
Author

  • Move this to miscellaneous.php.
  • Improve readability by adding curly brackets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment