Jump to content

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;
   }  


   
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.