Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $db_host = 'localhost';
- $db_port = '3306';
- $db_username = 'root';
- $db_password = 'root';
- $db_primaryDatabase = 'dsl_ams';
- // Connect to the database, using the predefined database variables in /assets/repository/mysql.php
- $dbConnection = new mysqli($db_host, $db_username, $db_password, $db_primaryDatabase);
- // If there are errors (if the no# of errors is > 1), print out the error and cancel loading the page via exit();
- if (mysqli_connect_errno()) {
- printf("Could not connect to MySQL databse: %sn", mysqli_connect_error());
- exit();
- }
- $queryCreateUsersTable = "CREATE TABLE IF NOT EXISTS `USERS` (
- `ID` int(11) unsigned NOT NULL auto_increment,
- `EMAIL` varchar(255) NOT NULL default '',
- `PASSWORD` varchar(255) NOT NULL default '',
- `PERMISSION_LEVEL` tinyint(1) unsigned NOT NULL default '1',
- `APPLICATION_COMPLETED` boolean NOT NULL default '0',
- `APPLICATION_IN_PROGRESS` boolean NOT NULL default '0',
- PRIMARY KEY (`ID`)
- )";
- if(!$dbConnection->query($queryCreateUsersTable)){
- echo "Table creation failed: (" . $dbConnection->errno . ") " . $dbConnection->error;
- }
- $query = "SELECT ID FROM USERS";
- $result = mysqli_query($dbConnection, $query);
- if(empty($result)) {
- $query = "CREATE TABLE USERS (
- ID int(11) AUTO_INCREMENT,
- EMAIL varchar(255) NOT NULL,
- PASSWORD varchar(255) NOT NULL,
- PERMISSION_LEVEL int,
- APPLICATION_COMPLETED int,
- APPLICATION_IN_PROGRESS int,
- PRIMARY KEY (ID)
- )";
- $result = mysqli_query($dbConnection, $query);
- }
- $query = "INSERT INTO USERS (EMAIL, PASSWORD, PERMISSION_LEVEL, APPLICATION_COMPLETED, APPLICATION_IN_PROGRESS) VALUES ('foobar@foobar.com', 'fjsdfbsjkbgs', 0, 0, 0)";
- $querycheck='SELECT 1 FROM `USERS`';
- $query_result=$dbConnection->query($querycheck);
- if ($query_result !== FALSE)
- {
- // table exists
- } else
- {
- // table does not exist, create here.
- }
- if(!$dbConnection->query($queryCreateUsersTable)){
- if($dbConnection->errno != 1050){
- echo "Table creation failed: (" . $dbConnection->errno . ") " . $dbConnection->error;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement