Class extend problem php5/mysql
Jeg har et lille problem. Jeg skal foretage et databaseudtræk ved hjælp af to class's: 1 for database connection og en for min SQL-query men kan ikke få skidtet til at virke.Kode:
core.classes.php:
class dbConnect {
public $conn;
//Method to connect to our database
public function __construct($host, $user, $pass, $db) {
$this->conn = mysqli_connect($host, $user, $pass, $db);
}
}
class sqlConnect{
//public $row;
//Method to select fields or all from our database
public function selectQuery($table, $id_field, $field, $colum, $where, $callback) {
if ($where != "") $where = "WHERE $where";
if ($field == "") $field = "*";
if ($table == "" || $callback == ""){
echo "En eller flere parametre mangler i selectQuery.";
exit();
}else{
$result = mysqli_query($this->conn, "SELECT $field FROM $table $where") or die(mysqli_error($this->conn));
}
//Lets loop through our rows in our database and then call our function to print the results
while ($row = mysqli_fetch_array($result)) {
$callback($row['email'],$row['welcome']);
}
}
//Function to print out our rows in the database and create a delete/update link
function echoQuery1($value){
echo "$value";
}
default.php:
$db = new dbConnect("localhost","root","****","database");
$sql= new sqlConnect();
//Parameters to send back: table name, id_field name, field name, colum name, where clause, function echoQuery1
$sql->selectQuery("site","","","","","echoQuery1");
Nogen ideer?
