PHP expert |
|
blijkbaar moest ik $obj->result in een variable zetten en die dan echoën.
old
hallo,
ik ben bezig met volgende code:
<?php
class mysql
{
private $host;
private $user;
private $password;
private $port;
private $db;
private $server;
private $database;
public $result;
/*
CONNECT FUNCTION
*/
public function connect($host, $user, $password, $port = 80, $db)
{
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->port = $port;
$this->db = $db;
$this->server = mysql_connect($this->host, $this->user, $this->password, $this->port);
$this->database = mysql_select_db($this->db);
}
/*
MYSQL SELECT FUNCTION
*/
public function select($velden, $tabel, $where = 1, $order = "id", $order_type = "ASC", $limit = 999)
{
$rQuery = "SELECT ";
//alle velden moeten in een array staan: $velden = array("id", "naam", "..");
$aantal = count($velden);
$i = 1;
foreach($velden as $key)
{
if($i == $aantal)
{
$rQuery .= $key;
}
else
{
$rQuery .= $key.",";
$i++;
}
}
$rQuery .= " FROM ";
$rQuery .= $tabel;
$rQuery .= " WHERE ";
$rQuery .= $where;
$rQuery .= " ORDER BY ";
$rQuery .= $order." ";
$rQuery .= $order_type;
$rQuery .= " LIMIT 0,";
$rQuery .= $limit;
echo $rQuery;
$this->$result = mysql_query($rQuery, $this->server);
if($this->result === FALSE)
{
die("Kan je selectie query niet uitvoeren om de reden:<br>".mysql_error());
}
else
{
return $this->result;
}
}
}
?>
<?php { private $host; private $user; private $password; private $port; private $db; private $server; private $database; public $result; /* CONNECT FUNCTION */ public function connect($host, $user, $password, $port = 80, $db) { $this->host = $host; $this->user = $user; $this->password = $password; $this->port = $port; $this->db = $db; $this->server = mysql_connect($this->host, $this->user, $this->password, $this->port); } /* MYSQL SELECT FUNCTION */ public function select($velden, $tabel, $where = 1, $order = "id", $order_type = "ASC", $limit = 999) { $rQuery = "SELECT "; //alle velden moeten in een array staan: $velden = array("id", "naam", ".."); $aantal = count($velden); $i = 1; foreach($velden as $key) { if($i == $aantal) { $rQuery .= $key; } else { $rQuery .= $key.","; $i++; } } $rQuery .= " FROM "; $rQuery .= $tabel; $rQuery .= " WHERE "; $rQuery .= $where; $rQuery .= " ORDER BY "; $rQuery .= $order." "; $rQuery .= $order_type; $rQuery .= " LIMIT 0,"; $rQuery .= $limit; if($this->result === FALSE) { die("Kan je selectie query niet uitvoeren om de reden:<br>".mysql_error()); } else { return $this->result; } } } ?>
nu wanneer ik echter in een nieuw document volgende code typ:
<?php
include("mysql_class.php");
$obj = new mysql;
$obj->connect("localhost", "*****", "*****", 80, "***");
$obj->select(array("id", "product", "aankoopdatum"), "betalingen", 1, "product", "DESC");
echo mysql_num_rows($obj->result);
?>
<?php include("mysql_class.php"); $obj->connect("localhost", "*****", "*****", 80, "***"); $obj->select(array("id", "product", "aankoopdatum"), "betalingen", 1, "product", "DESC"); ?>
dan geeft hij volgende weer:
SELECT id,product,aankoopdatum FROM betalingen WHERE 1 ORDER BY product DESC LIMIT 0,999
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\wamp\www\scripts\mysql.php on line 10
volgens mij is het de source, ik denk $this->result, maar ik vind de fout niet raar nochtans staat hij op public...
kan iemand me verderhelpen?
groeten
stijn
|