Jump to content

It was working, now it isn't...


Archadian

Recommended Posts

On my homepage i am getting this:

 

Warning: Missing argument 1 for Mysql::__construct(), called in F:\Inetpub\wwwroot\index.php on line 38 and defined in F:\Inetpub\wwwroot\include\class.php on line 18

 

Warning: Missing argument 2 for Mysql::__construct(), called in F:\Inetpub\wwwroot\index.php on line 38 and defined in F:\Inetpub\wwwroot\include\class.php on line 18

 

Warning: Missing argument 3 for Mysql::__construct(), called in F:\Inetpub\wwwroot\index.php on line 38 and defined in F:\Inetpub\wwwroot\include\class.php on line 18

 

Warning: Missing argument 4 for Mysql::__construct(), called in F:\Inetpub\wwwroot\index.php on line 38 and defined in F:\Inetpub\wwwroot\include\class.php on line 18

 

Warning: Missing argument 5 for Mysql::__construct(), called in F:\Inetpub\wwwroot\index.php on line 38 and defined in F:\Inetpub\wwwroot\include\class.php on line 18

Please check the Cabal connection.

 

here is the class.php section that is causing it:

 

class Mysql
{

private $host = 'localhost';
private $user = 'user';
private $pass = 'pass';
private $result = '';
private $db = '';

public function __construct($host, $user, $pass, $result, $db) {

	$this->host = $host;
	$this->user = $user;
	$this->pass = $pass;
	$this->result = $result;
	$this->db = $db;

}
public function cabal() {

	$filename = dirname(__FILE__);

	if (preg_match('/wwwroot/', $filename)) {

		$this->db = 'cabalweb';

	}

$conn = @mysql_connect($this->host, $this->user, $this->pass);
$this->result = @mysql_select_db($this->db);

if(!$conn || !$this->result) {

	die('Please check the Cabal connection.');

}

return $this->result;

}

public function forums() {

	$filename = dirname(__FILE__);

	if (preg_match('/forums/', $filename)) {

		$this->db = 'c_forums';

	}

	$conn = @mysql_connect($this->host, $this->user, $this->pass);
	$this->result = @mysql_select_db($this->db);

	if(!$conn || !$this->result) {

		die('Please check the Forums connection.');

	}

	return $this->result;

}

}

 

and here is the lines around line 38 on index.php:

 

require('include/class.php');

$db =& new Mysql(); //line 38
$db->cabal();

 

It was working fine, I did not change anything and all of a sudden it stops working and gives me the warning messages. Any ideas on what this could be or what is wrong in the code? Thanks.

Link to comment
https://forums.phpfreaks.com/topic/128494-it-was-working-now-it-isnt/
Share on other sites

Thanks that worked but why wouldn't this work?

 

private $host = 'localhost';
private $user = 'user';
private $pass = 'pass';
private $result = '';
private $db = '';

public function __construct($host, $user, $pass, $result, $db) {

 

If $host = localhost, $user = username, $pass = password is being set why wouldn't it work for the __contruct()? Or is that just for the other variables in the other functions of the class? Thanks.

That wouldn't work because those have nothing to do with the parameters names. Those are private properties that have the same names as the parameters in the __construct()

 

Also a note from the manual:

 

Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.

 

And the & to have the reference is not necessary

 

$db =& new Mysql()

Your class should look like this (or similar):

 

Notice how I broke up the commonality in to common methods, so that they can be reused and changed in a single place.

<?php
class Mysql
{
   
   private $host = 'localhost';
   private $user = 'user';
   private $pass = 'pass';
   private $result = '';
   private $db = '';
   
   public function __construct() { }

   public function set_db($name) {
       $filename = dirname(__FILE__);
       if (preg_match('/wwwroot/', $filename)) {
   
          $this->db = $name;
       }       
   }

   public function get_db_connection() {
      $conn = @mysql_connect($this->host, $this->user, $this->pass);
      $this->result = @mysql_select_db($this->db);
   
      if(!$conn || !$this->result) {
          die('Please check the Cabal connection.');
      }
   
       return $this->result;
   }  


   
}
?>

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.