...

View Full Version : OOP Problem



Kev0121
03-28-2009, 06:24 PM
Well trying to do simple querys with oop, heres my script

getting this error



Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\register_oop\database.php on line 24




<?php

class Database {
var $conn;
var $dbs;

public function connect() {
$this->conn = mysql_connect('localhost','root','');
$this->dbs = mysql_select_db('test',$this->conn);
}

public function query($sql) {
$res = mysql_query($sql);
$this->conf_query($res);
}

public function conf_query($res) {
if(!$res) {
die("Database query error ". mysql_error());
}
}

public function fetch_array($result_set) {
return mysql_fetch_array($result_set);
}


public function num_rows($result_set) {
return mysql_num_rows($result_set);
}
}

$database = new Database();
$database->connect();

?>


heres my query



<?php
require_once('database.php');

$sql = "SELECT * FROM test WHERE id = 1";
$result_set = $database->query($sql);
$found_user = $database->fetch_array($result_set);



?>

abduraooft
03-28-2009, 06:33 PM
You need to return the result set,

public function query($sql) {
$res = mysql_query($sql);
$this->conf_query($res);
return($res);
} for your
$result_set = $database->query($sql); statement.

Kev0121
03-28-2009, 06:36 PM
Thanks alot!!!

Kevin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum