<?php
class Functions {
public static function extendSql($dbhost, $dbuser, $dbpass, $dbname) {
// making the mysql connection dynamically editable
$mysql_connect = mysql_connect($dbhost, $dbuser, $dbpass)or die("Could not connect: " . mysql_error());
$mysql_select_db = mysql_select_db($dbname) or die(mysql_error());
}
public static function whileLoop($dbuser, $dbpass, $dbname, $sql, $passedData) {
$this->extendSql($dbuser, $dbpass, $dbname);
$results = mysql_query($sql);
while ($row = mysql_fetch_array($results)) {
echo $passedData;
}
}
}
Functions::whileLoop("root", "", "rand", "SELECT * FROM products",
$hello = "hi all");
?>
I get the following error when I execute the above code.
Fatal error: Using $this when not in object context in
C:\Workspace\htdocs\Misc-2\nurbell1\core\conf\misc.php on line 13
What am I doing wrong? Obviously, $this is referenced inside the classed context in my code.
You are using
$thisin a static function, which doesn´t belong to the current instance/context, and thus is unable to use$this.