Welcome Guest, Not a member yet? Register   Sign In
Database problem
#3

You can use this to test to make sure that MySQLi is working correct.

PHP Code:
<?php
// Code to create the database

$serverName "localhost";
$userName   "username";
$password   "password";

// Create the Database Connection
$connId mysqli_connect($serverName$userName$password);

// Check the Database Connection
if ($connId === false)
{
 
   exit("ERROR: Could not connect. " mysqli_connect_error());


// Create the Database
$sql "CREATE DATABASE yourDatabaseName";

// Check that the Database was created
if (mysqli_query($connId$sql))
{
 
   echo "Database created successfully";
}
else
{
 
   echo "ERROR: Creating Database. " mysqli_error($connId);
}

// Close the Connection
mysqli_close($connId);

?>

// Code to create database tables

<?php
$serverName 
"localhost";
$userName   "username";
$password   "password";

// Attempt MySQL server connection. Assuming you are running MySQL server
$connId mysqli_connect($serverName$userName$password);
 
// Check connection
if ($connId === false)
{
 
   exit("ERROR: Could not connect. " mysqli_connect_error());
}
 
// Attempt create table query execution
$sql "CREATE TABLE persons(person_id INT(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, first_name CHAR(30) NOT NULL, last_name CHAR(30) NOT NULL, email_address VARCHAR(50))";

if (
mysqli_query($connId$sql))
{
 
   echo "Table persons created successfully";
}
else
{
 
   echo "ERROR: Could not able to execute $sql. " mysqli_error($connId);
}
 
// Close connection
mysqli_close($connId);
?>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
Database problem - by quaymat321234 - 05-20-2017, 04:39 AM
RE: Database problem - by webdev25 - 05-20-2017, 05:21 AM
RE: Database problem - by InsiteFX - 05-20-2017, 08:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB