Jump to content

couple MySQLI issues i cant seem to figure out.


cbuck1989

Recommended Posts

So I am going to look like a complete noob (which i am haha) but I cannot for the life of me get these issues fixed.

 

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 4

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 5

 

 

here is the code in constant.php

<?php
$boo = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
mysqli_select_db($boo, SQL_DB);
$sql = mysqli_query($boo, "SELECT * FROM ".TB_PREFIX."config");
$result = mysqli_fetch_array($sql);

If anyone could please tell me what i am messing up here, would be much appreciated.

 

Thank you

Link to comment
Share on other sites

Okay ill just post all the error messages and pages.

 

 

 

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 4

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 5

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.phpon line 25

Warning: Cannot modify header information - headers already sent by (output started at /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php:4) in /home1/cbuck1989/trav.flyingroadside.com/install/process.php on line 80

 

Okay so you already see constant.php

 

here is Database.php

<?php

set_time_limit(0); 
include("connection.php");
include("constant.php");

class MYSQLi_DB {
	
	var $connection;
	
	function MYSQLi_DB() {
		$this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB) or die(mysqli_error());
	}
		function query($query) {
		return $this->connection->query($query);
		}
		
};

class MYSQL_DB {
	
	var $connection;
	
	function MYSQL_DB() {
		$this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error());
		mysql_select_db(SQL_DB, $this->connection) or die(mysql_error());
	}
	
	function mysql_exec_batch ($p_query, $p_transaction_safe = true) {
  if ($p_transaction_safe) {
      $p_query = 'START TRANSACTION;' . $p_query . '; COMMIT;';
    };
  $query_split = preg_split ("/[;]+/", $p_query);
  foreach ($query_split as $command_line) {
    $command_line = trim($command_line);
    if ($command_line != '') {
      $query_result = mysql_query($command_line);
      if ($query_result == 0) {
        break;
      };
    };
  };
  return $query_result;
} 

	function query($query) {
		return mysql_query($query, $this->connection);
	}
};

if(DB_TYPE) {
	$database = new MYSQLi_DB;
}
else {
	$database = new MYSQL_DB;
}
?>

and here is process.php

<?php

date_default_timezone_set('Asia/Tehran');
        if(file_exists("include/constant.php") && file_exists("include/connection.php")) {
        	include ("include/database.php");
        }
        class Process {

        	function Process() {
        		if(isset($_POST['subconst'])) {
        			$this->constForm();
        		} else
        			if(isset($_POST['substruc'])) {
        				$this->createStruc();
        			} else
        				if(isset($_POST['subwdata'])) {
        					$this->createWdata();
        				} else
        					if(isset($_POST['subacc'])) {
        						$this->createAcc();
        						} else {
        							header("Location: index.php");
        						}
        	}

        	function constForm() {
				global $database;
        		$myFile = "include/constant.php";
        		$fh = fopen($myFile, 'w') or die("<br/><br/><br/>Can't open file: install\include\constant.php");
        		$text = file_get_contents("data/constant_format.tpl");
				$text = preg_replace("'%TRADERCAP%'", $_POST['tradercap'], $text);
				$text = preg_replace("'%CRANNYCAP%'", $_POST['crannycap'], $text);
				$text = preg_replace("'%TRAPPERCAP%'", $_POST['trappercap'], $text);
        		$text = preg_replace("'%UTRACK%'", $_POST['trackusers'], $text);
        		$text = preg_replace("'%UTOUT%'", $_POST['timeout'], $text);
        		$text = preg_replace("'%AUTOD%'", $_POST['autodel'], $text);
        		$text = preg_replace("'%AUTODT%'", $_POST['autodeltime'], $text);
        		$text = preg_replace("'%MAX%'", $_POST['wmax'], $text);
        		$text = preg_replace("'%ANAME%'", $_POST['aname'], $text);
        		$text = preg_replace("'%ARANK%'", $_POST['admin_rank'], $text);
        		$text = preg_replace("'%STARTTIME%'", time(), $text);
        		$text = preg_replace("'%LIMIT_MAILBOX%'", $_POST['limit_mailbox'], $text);
        		$text = preg_replace("'%MAX_MAILS%'", $_POST['max_mails'], $text);
        		$text = preg_replace("'%VILLAGE_EXPAND%'", $_POST['village_expand'], $text);
        		$text = preg_replace("'%ERROR%'", $_POST['error'], $text);
        		$text = preg_replace("'%GREAT_WKS%'", $_POST['great_wks'], $text);
        		$text = preg_replace("'%TS_THRESHOLD%'", $_POST['ts_threshold'], $text);
				$text = preg_replace("'%SSTARTDATE%'", $_POST['start_date'], $text);
				$text = preg_replace("'%SSTARTTIME%'", $_POST['start_time'], $text);
				$text = preg_replace("'%REG_OPEN%'", $_POST['reg_open'], $text);
				$text = preg_replace("'%PEACE%'", $_POST['peace'], $text);
				$text = preg_replace("'%LIMIT_TROOPS%'", $_POST['limit_troops'], $text);
				$text = preg_replace("'%STORAGE_MULTIPLIER%'", $_POST['storage_multiplier'], $text);
        		fwrite($fh, $text);
				fclose($fh);
				
				$myFile = "include/connection.php";
        		$fh = fopen($myFile, 'w') or die("<br/><br/><br/>Can't open file: install\include\connection.php");
        		$text = file_get_contents("data/connection.tpl");
        		$text = preg_replace("'%SSERVER%'", $_POST['sserver'], $text);
        		$text = preg_replace("'%SUSER%'", $_POST['suser'], $text);
        		$text = preg_replace("'%SPASS%'", $_POST['spass'], $text);
        		$text = preg_replace("'%SDB%'", $_POST['sdb'], $text);
        		$text = preg_replace("'%PREFIX%'", $_POST['prefix'], $text);
        		$text = preg_replace("'%CONNECTT%'", $_POST['connectt'], $text);

        		fwrite($fh, $text);
				
        		if(file_exists("include/constant.php") && file_exists("include/connection.php")) {
					include 'include/database.php';
					$str = file_get_contents("data/config.sql");
        			$str = preg_replace("'%PREFIX%'", TB_PREFIX, $str);
					if(DB_TYPE) {
        				$database->connection->multi_query($str);
        			} else {
        				$database->mysql_exec_batch($str);
        			}
					mysql_query("INSERT into ".$_POST['prefix']."config values ('".$_POST['servername']."', '".$_POST['lang']."', '".$_POST['speed']."', 'gpack/travian_Travian_4.0_41/', '".$_POST['incspeed']."', '".$_POST['evaspeed']."', '".$_POST['healspeed']."', '".$_POST['advspeed']."', '".$_POST['demolish']."', '".$_POST['quest']."', '".$_POST['beginner']."', '".$_POST['auction_time']."', '".$_POST['ww']."', '".$_POST['activate']."', '".$_POST['plus_time']."', '".$_POST['plus_production']."', '".$_POST['log_build']."', '".$_POST['log_tech']."', '".$_POST['log_login']."', '".$_POST['log_gold_fin']."', '".$_POST['log_admin']."', '".$_POST['log_war']."', '".$_POST['log_market']."', '".$_POST['log_illegal']."', '".$_POST['box1']."', '".$_POST['box2']."', '".$_POST['box3']."', '".$_POST['home1']."', '".$_POST['home2']."', '".$_POST['home3']."', '".$_POST['aemail']."', '".$_POST['homepage']."')");
					
        			header("Location: index.php?s=2");
        		} else {
        			header("Location: index.php?s=1&c=1");
        		}

        		fclose($fh);
        	}

        	function createStruc() {
        		global $database;
        		$str = file_get_contents("data/sql.sql");
        		$str = preg_replace("'%PREFIX%'", TB_PREFIX, $str);
        		if(DB_TYPE) {
        			$result = $database->connection->multi_query($str);
        		} else {
        			$result = $database->mysql_exec_batch($str);
        		}
        		if($result) {
        			header("Location: index.php?s=3");
        		} else {
        			header("Location: index.php?s=2&c=1");
        		}
        	}

        	function createWdata() {
        		header("Location: include/wdata.php");
        	}
            
        }
        ;

        $process = new Process;

?>

I mean ive looked over and tried to fix the things it listed but i get no where. I hate how SQL is removed and put in SQLI. Cause now all my old coding needs updated.

 

I apologize for being so "dumb" about this. It used to be easier back in the day it seems. I haven't tinkered with coding in many years haha

Link to comment
Share on other sites

Let's stay on the first post for now.

 

How about checking the result of your connect call? Test the value of $boo.

 

If that fails try this. Build the query statement in a var - say $q. Then echo out that variable $q to see what you have built and are actually executing.

Link to comment
Share on other sites

The first two errors are referring to the file constant.php. It states that mysqli_query() is only being provided one parameter, but it lookslike two are provided

 

$sql = mysqli_query($boo, "SELECT * FROM ".TB_PREFIX."config");

 

Perhaps $boo is false/null? You should add some debugging code to the connection and database selection functions.

 

$boo = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
if (!$boo) {
    echo "Error: Unable to connect to MySQL.<br>";
    echo "Debugging errno: " . mysqli_connect_errno() . "";
    echo "Debugging error: " . mysqli_connect_error() . "<br>";
    exit;
}
$selectDbResult = mysqli_select_db($boo, SQL_DB);
if (!$selectDbResult) {
    echo "Error: Unable to Select DB.<br>";
    exit;
}

 

As for the other errors - why are you using mysql_ extensions and not mysqli_? That is just a warning message - which you can suppress, but you should be using mysqli_ or, better yet, PDO.

Link to comment
Share on other sites

The first two errors are referring to the file constant.php. It states that mysqli_query() is only being provided one parameter, but it lookslike two are provided

$sql = mysqli_query($boo, "SELECT * FROM ".TB_PREFIX."config");

Perhaps $boo is false/null? You should add some debugging code to the connection and database selection functions.

$boo = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS);
if (!$boo) {
    echo "Error: Unable to connect to MySQL.<br>";
    echo "Debugging errno: " . mysqli_connect_errno() . "";
    echo "Debugging error: " . mysqli_connect_error() . "<br>";
    exit;
}
$selectDbResult = mysqli_select_db($boo, SQL_DB);
if (!$selectDbResult) {
    echo "Error: Unable to Select DB.<br>";
    exit;
}

As for the other errors - why are you using mysql_ extensions and not mysqli_? That is just a warning message - which you can suppress, but you should be using mysqli_ or, better yet, PDO.

 

Okay so i did that and now the first 2 error messages went away. now i just have the last 2

 

 

 

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.phpon line 25

 

Warning: Cannot modify header information - headers already sent by (output started at /home1/cbuck1989/trav.flyingroadside.com/install/include/database.php:25) in /home1/cbuck1989/trav.flyingroadside.com/install/process.php on line 80

Link to comment
Share on other sites

now i get this error

 

 

 

Fatal error: Cannot redeclare class mysqli_DB in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.php on line 20

 

 

database.php:

<?php

set_time_limit(0); 
include("connection.php");
include("constant.php");

class MYSQLi_DB {
	
	var $connection;
	
	function MYSQLi_DB() {
		$this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB) or die(mysqli_error());
	}
		function query($query) {
		return $this->connection->query($query);
		}
		
};

class mysqli_DB {
	
	var $connection;
	
	function mysqli_DB() {
		$this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysqli_error());
		mysqli_select_db(SQL_DB, $this->connection) or die(mysqli_error());
	}
	
	function mysqli_exec_batch ($p_query, $p_transaction_safe = true) {
  if ($p_transaction_safe) {
      $p_query = 'START TRANSACTION;' . $p_query . '; COMMIT;';
    };
  $query_split = preg_split ("/[;]+/", $p_query);
  foreach ($query_split as $command_line) {
    $command_line = trim($command_line);
    if ($command_line != '') {
      $query_result = mysqli_query($command_line);
      if ($query_result == 0) {
        break;
      };
    };
  };
  return $query_result;
} 

	function query($query) {
		return mysqli_query($query, $this->connection);
	}
};

if(DB_TYPE) {
	$database = new MYSQLi_DB;
}
else {
	$database = new mysqli_DB;
}
?>

this is frustrating. 

Link to comment
Share on other sites

this is frustrating.

Quite.

 

What are you trying to do in that file? Why do you need two classes? Why are they identical except for that mysqli_exec_batch method in the second version? What is DB_TYPE supposed to control?

Link to comment
Share on other sites

It is a game. I downloaded it but as you can see the SQL stuff is not updated. So this is what ive been trying to figure out the past couple day haha.

 

This is just to install the game with its install feature. But everything works up to this point. But when you type in all the information on the install page it asks for you know the database information, and then theirs a drop down list that has MySQL and MySQLI. But the SQLI one is greyed out and cant select it. So im guessing that means i have to figure out the mess on these pages.

 

not sure if that helped at all xD

Link to comment
Share on other sites

When was the code you downloaded written? It's using old-style class constructors that are deprecated in 7.0 (if you scroll down a bit you'll see the warning about the deprecation). Also, the second declaration of query() isn't using mysqli_query() correctly - the connection and query are passing in the wrong order. Finally, I could be missing something here but the mysqli_exec_batch() method looks really very dangerous...

Link to comment
Share on other sites

I know the MySQLI is installed cause its through my web hosting provider which is using the new stuff.I have the same exact game but an older version of it that was converted over to mySQLI and it runs perfect. But the newer version of the game they didn't convert to the mysqli. Well bits and pieces are. It even said the installation is the buggiest part. So if i can get past the installation part ill be set.

Link to comment
Share on other sites

Blindly throwing code at the problem is not going to make it go away. Especially if you don't know what you're doing.

 

Your first step should be to find out why the mysqli option was disabled. The second step is to address the underlying cause.

Link to comment
Share on other sites

Did you change this:

  • class MYSQL_DB {
to this?
  • class MYSQLi_DB {
Because he said make your code use mysqli functions ... he didn't say to rename the classes.

 

If you did, you created this error:

 

Fatal error: Cannot redeclare class mysqli_DB in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.php on line 20

 

Because the code in database.php already had THIS at line 20:

 

      class mysqli_DB {

 

So I am going to look like a complete noob (which i am haha)

I don't like to call people names, but unfortunately this is starting to look like a more & more accurate statement. If we ARE able to make you see any light, you might have to apologize for wasting somebody's time. Although we volunteer it, or we wouldn't be here ... still people shouldn't take advantage of others like that.

 

Yeah, and if you have a car that doesn't work, you can just take the engine from another car and drop it in. Cause at least the other one works.

Well ... it's kind of like that. But you don't try that unless you're a mechanic or a very avid DIY type.

 

Same goes here.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.