Using mysqli on my localhost and it works as intended.
I upload it to the server with changed database name, username and password and it comes back “No database selected”
It is querying data fine from the database as I can populate tables with already existing data from the database, but I cannot Insert, Delete, Update. I always get “No database selected”
[php]<?php
class MySQLHandler {
// Offline Database connect
var $DATABASE = ‘fear’;
var $USERNAME = ‘root’;
var $PASSWORD = ‘’;
var $SERVER = ‘localhost’;
var $SHOW_ERRORS = true;
// Do not change the variables below
var $CONNECTION;
var $FILE_HANDLER;
var $ERROR_MSG = ‘’;
function init() {
if ($this->OpenConnection()) {
return true;
} else {
return false;
}
}
function OpenConnection() {
$conn = new mysqli($this->SERVER,$this->USERNAME,$this->PASSWORD);
if ((!$conn) || (!mysqli_select_db($conn,$this->DATABASE))) {
$this->ERROR_MSG = "\r\n" . "Unable to connect to database ";
$this->debug();
return false;
} else {
$this->CONNECTION = $conn;
return true;
}
}
function CloseConnection() {
if (mysqli_close($this->CONNECTION)) {
return true;
} else {
$this->ERROR_MSG = "\r\n" . "Unable to close database connection";
$this->debug();
return false;
}
}
function debug() {
if ($this->SHOW_ERRORS) {
echo $this->ERROR_MSG;
}
}
function Insert($sql) {
if ((empty($sql)) || (!explode("^insert",$sql)) || (empty($this->CONNECTION))) {
$this->ERROR_MSG = "\r\n" . "SQL Statement is <code>null</code> or not an INSERT";
$this->debug();
return false;
} else {
$conn = $this->CONNECTION;
$results = mysqli_query($conn,$sql);
if (!$results) {
$this->ERROR_MSG = "\r\n" . mysqli_error();
$this->debug();
return false;
} else {
$result = mysqli_insert_id();
return $result;
}
}
}
function Select($sql) {
if ((empty($sql)) || (!explode("^select",$sql)) || (empty($this->CONNECTION))) {
$this->ERROR_MSG = "\r\n" . "SQL Statement is <code>null</code> or not a SELECT";
$this->debug();
return false;
} else {
$conn = $this->CONNECTION;
$results = mysqli_query($conn,$sql);
if ((!$results) || (empty($results))) {
$this->ERROR_MSG = "\r\n" . mysql_error();
$this->debug();
return false;
} else {
$i = 0;
$data = array();
while ($row = mysqli_fetch_array($results)) {
$data[$i] = $row;
$i++;
}
mysqli_free_result($results);
return $data;
}
}
}
function Update($sql) {
if ((empty($sql)) || (!explode("^update",$sql)) || (empty($this->CONNECTION))) {
$this->ERROR_MSG = "\r\n" . "SQL Statement is <code>null</code> or not an UPDATE";
$this->debug();
return false;
} else {
$conn = $this->CONNECTION;
$results = mysqli_query($conn,$sql);
if (!$results) {
$this->ERROR_MSG = "\r\n" . mysql_error()." - " . date('H:i:s');
$this->debug();
return false;
} else {
return mysqli_affected_rows($conn);
}
}
}
function Replace($sql) {
if ((empty($sql)) || (!explode("^replace",$sql)) || (empty($this->CONNECTION))) {
$this->ERROR_MSG = "\r\n" . "SQL Statement is <code>null</code> or not a REPLACE";
$this->debug();
return false;
} else {
$conn = $this->CONNECTION;
$results = mysqli_query($conn,$sql);
if (!$results) {
$this->ERROR_MSG = "\r\n" . "Error in SQL Statement : ($sql)";
$this->debug();
return false;
} else {
return true;
}
}
}
function Delete($sql) {
if ((empty($sql)) || (!explode("^delete",$sql)) || (empty($this->CONNECTION))) {
$this->ERROR_MSG = "\r\n" . "SQL Statement is <code>null</code> or not a DELETE";
$this->debug();
return false;
} else {
$conn = $this->CONNECTION;
$results = mysqli_query($conn,$sql);
if (!$results) {
$this->ERROR_MSG = "\r\n" . mysql_error();
$this->debug();
return false;
} else {
return true;
}
}
}
function Query($sql) {
if ((empty($sql)) || (empty($this->CONNECTION))) {
$this->ERROR_MSG = "\r\n" . "SQL Statement is <code>null</code>";
$this->debug();
return false;
} else {
$conn = $this->CONNECTION;
$results = mysqli_query($conn,$sql);
if (!$results) {
$this->ERROR_MSG = "\r\n" . mysql_error();
$this->debug();
return false;
} else {
return true;
}
}
}
}
?>[/php]
With $sql being
[php]$this->sql->update(“UPDATE battle_attendance SET status = '”.$status."’ WHERE battleid = ‘".$id."’ AND user_id = ‘".$user_id."’ ");[/php]
Any ideas?