Jump to content

PHP Error


RayToolbear

Recommended Posts

I keep getting this error when running my script. Bellow is the script I have all the file: <?phpif(!defined("DBCONF")){ define("DBCONF", true); include('iCPdb.php');}define("DB_INCLUDED", true);define("BAD_USER", false);define("VALID_USER", true);$g_link = false;function &getDB(){ global $g_link; if( @$g_link && is_object($g_link)) return $g_link; if(DB_HOST != "localhost" && DB_HOST != "127.0.0.1"){ $g_link = mysqli_init(); $g_link->real_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, null, null, MYSQLI_CLIENT_COMPRESS); } else{ $g_link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); } @$g_link->autocommit(false);//false for MyISAM! echo "Connected to MySQL server " . DB_HOST . " username " . DB_USER . "\n"; //$g_link = mysql_connect( 'localhost', 'root', 'E9hfAZLCvU5W') or die('Could not connect to server.' ); //mysql_select_db('penguins', $g_link) or die('Could not select database.'); return $g_link;}function DBCommit(){ $g_link = getDB(); return $g_link->commit(); //return true;//For InnoDB}function getData($query, $m = "default"){ error_reporting(E_ALL | E_STRICT); $mysqli = getDB(); $result = $mysqli->query($query); if(!is_object($result)){ return false; } $row = $result->fetch_assoc(); if($m == "single"){ if(is_object($result)) $result->close(); return $row; } $a = array($row); while($d2 = $result->fetch_assoc()){ $a[] = $d2; } if(is_object($result)) $result->close(); return $a;}function setData($query){ $mysqli = getDB(); $result = $mysqli->query($query); $return = ($result === false) ? false :true; if(is_object($result)) $result->close(); return $return;}function validUser($name){ $d = getData("SELECT ID from accs WHERE UCASE(name) = '" . dbEscape(strtoupper($name)) . "'"); if($d[0] == false || (!is_array($d)) || (count($d) < 1) || $d == false){ return BAD_USER; } if(count($d) !== 1){ //$this->logger->error("ERROR: getData call returned multiple usernames for a UNIQUE query. Your database is corrupted!"); return VALID_USER;//It still exists, and this should never happen... so... just in case } return VALID_USER;}function validID($id){ $d = getData("SELECT name from accs WHERE ID = '" . dbEscape($id) . "'"); if($d[0] === false || (!is_array($d)) || (count($d) < 1)){ return BAD_USER; } if(count($d) !== 1){ $this->logger->error("ERROR: getData call returned multiple usernames for a UNIQUE query. Your database is corrupted!"); return VALID_USER;//It still exists, and this should never happen... so... just in case } return VALID_USER;}function getId($name){ $d = getData("SELECT ID from accs where UCASE(name) = '" . dbEscape(strtoupper($name)) . "'"); if($d[0] === false || (!is_array($d)) || (count($d) < 1)){ return BAD_USER; } if(count($d) !== 1){ $this->logger->error("ERROR: getData call returned multiple usernames for a UNIQUE query. Your database is corrupted!"); //return BAD_USER; //It still exists, and this should nevaar happen... so... just in case } return $d[0]['ID'];}function getName($ID){ $d = getData("SELECT name from accs where ID = '" . dbEscape($ID) . "'"); if($d[0] === false || (!is_array($d)) || (count($d) < 1)){ return BAD_USER; } if(count($d) !== 1){ $this->logger->error("ERROR: getData call returned multiple usernames for a UNIQUE query. Your database is corrupted!"); //return BAD_USER; //It still exists, and this should nevaar happen... so... just in case } return $d[0]['name'];}function getIglooDetails($id){ if(!validID($id)) return BAD_USER; $a = (getData("SELECT crumbs FROM accs WHERE ID=" . dbEscape($id), "single")); if(!$a) return BAD_USER; $a = unserialize($a['crumbs']); if(!is_array($a)) return BAD_USER; $s = $id; if(!isset($a["igloo"])){ return $s .= "%0%0%0"; } $s .= "%" . $a["igloo"]; $s .= "%" . $a["music"]; $s .= "%" . $a["floor"]; if(@$a["roomFurniture"]){ $s .= "%" . $a["roomFurniture"]; $s = substr($s, 0, strlen($s) - 1); } return $s;}function getPlayer($id){ $a = (getData("SELECT crumbs FROM accs WHERE ID=" . dbEscape($id), "single")); if(!$a) return BAD_USER; $a = unserialize($a['crumbs']); if(!is_array($a)) return BAD_USER; $s = $id; $s .= "|" . getName($id) . "|" . 1;//ENGLISH BITMASK! $s .= "|" . $a["color"]; $s .= "|" . $a["head"]; $s .= "|" . $a["face"]; $s .= "|" . $a["neck"]; $s .= "|" . $a["body"]; $s .= "|" . $a["hands"]; $s .= "|" . $a["feet"]; $s .= "|" . $a["pin"]; $s .= "|" . $a["photo"] . "|"; return $s;}function dbEscape($s, $link = NULL){ $mysqli = getDB(); return $mysqli->real_escape_string($s);}function finishDB(){ global $g_link; if($g_link) @mysql_close($g_link); $g_link = false;}function makeXt(){ $a = func_get_args(); if(!is_array($a)) return false; $send = "%xt%"; foreach($a as $s){ $send .= $s . "%"; } return $send;}function getPlayersStamps($id){ $a = (getData("SELECT crumbs FROM accs WHERE ID=" . dbEscape($id), "single")); if(!$a) return BAD_USER; $a = unserialize($a['crumbs']); if(!is_array($a)) return BAD_USER; $s = $id; if(!count($a["stamps"])){ return $s; } $s .= "%"; foreach($a["stamps"] as $stamp){ $s .= "$stamp|"; } $s = substr($s, 0, strlen($s) - 1); return $s;}function queryPlayersPins($id){ $a = (getData("SELECT crumbs FROM accs WHERE ID=" . dbEscape($id), "single")); if(!$a) return BAD_USER; $a = unserialize($a['crumbs']); if(!is_array($a)) return BAD_USER; $items = $a["items"]; $pins = ""; foreach($items as $item){ if(($item >= 500 and $item < 650) || ($item >= 7000 and $item < 7100)){ //temporary pin check $pins .= "$item|0000000000|0%"; //0000000000 = pin release date in unix time, not sure what third parameter } } $pins = substr($pins, 0, strlen($pins) - 1); return $pins;}function getStampBookCoverDetails($id){ $a = (getData("SELECT crumbs FROM accs WHERE ID=" . dbEscape($id), "single")); if(!$a) return BAD_USER; $a = unserialize($a['crumbs']); if(!is_array($a)) return BAD_USER; if(!isset($a["stampColor"])){ return $s = "1%1%-1%1"; } $s = $a["stampColor"]; $s .= "%" . $a["stampHighlight"]; $s .= "%" . $a["stampPattern"]; $s .= "%" . $a["stampIcon"]; return $s;}function userOnline($id){ $a = (getData("SELECT crumbs FROM accs WHERE ID=" . dbEscape($id), "single")); if(!$a) return BAD_USER; $a = unserialize($a['crumbs']); if(!is_array($a)) return BAD_USER; if(isset($a['online'])) if($a['online']) return $a['lastServerID']; return false;}function updateStatus($id, $online){ $query = "INSERT INTO stats VALUES($id," . dbEscape($online) . "," . ($time = time()) . ") ON duplicate KEY UPDATE population=" . dbEscape($online) . ", ts=$time"; $res = setData($query); //echo "DEBUG: updated stats, query $query!\n";}?>-------------------Errors: PHP Error: 8: Use of undefined constant DB_HOST - assumed 'DB_HOST', in /home/test/INCLUDES/Database.php at 17!PHP Error: 8: Use of undefined constant DB_HOST - assumed 'DB_HOST', in /home/test/INCLUDES/Database.php at 17!PHP Fatal error: Call to undefined function mysqli_init() in /home/test/INCLUDES/Database.php on line 18PHP Error: 1: Call to undefined function mysqli_init(), in /home/test/INCLUDES/Database.php at 18!---------------iCPdb.php file:<?php define("DB_HOST", "localhost");define("DB_USER", "root");define("DB_PASS", "");define("DB_NAME", "iCP");?>

Link to comment
Share on other sites

I can suggest using $DB_HOST = 'localhost'; way.Or in other way instead of:

if(!defined("DBCONF")){  define("DBCONF", true);  include('iCPdb.php');}

just use

include 'iCPdb.php';

I even don't understand why people use such a things like this.And for mysqli_init() error. If you don't solve anything use standard mysql_connect() and mysql_select_db() etc :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...