0

I copied this code from w3schools and tried running it. I get a display till "Create connection." Then neither the error message nor success message.
I have ensured following commands for error reporting as well, but I am still getting a blank page:

<?php

    ini_set('display_errors', 'On');
    ini_set('html_errors', 0);
    error_reporting(-1);
    $servername = "localhost";
    $username = "root";
    $password = "root@123";

    echo "Create connection";
    $conn = new mysqli($servername, $username, $password);
    echo "Check connection";
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // Create database
    $sql = "CREATE DATABASE myDB";
    if ($conn->query($sql) === TRUE) {
        echo "Database created successfully";
    } else {
        echo "Error creating database: " . $conn->error;
    }

    echo "closing";
    $conn->close();
    ?> 

Can anyone tell me what the issue is?

b.g
  • 411
  • 1
  • 3
  • 19
  • Up your [error_reporting](http://php.net/error_reporting), enable [display_errors](http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors), or check your errors logs and find out what's going on. – Jonnix Sep 08 '16 at 14:44
  • Then probably the script crashed, and you have display_errors and error_reporting turned off. They should NEVER be off on a debug/devel copy of PHP. – Marc B Sep 08 '16 at 14:44
  • What version SQL do you have? Is that the correct credentials for `$servername`, `$username`, `$password`? –  Sep 08 '16 at 14:44
  • Oh, also, if you're using mod_php + apache, remember to restart the apache process. Also, please look at your phpinfo output and see what mysql directives are listed. – Jonnix Sep 08 '16 at 14:45
  • error_reporting(-1); -> to turn on error reporting – M. I. Sep 08 '16 at 14:45

0 Answers0