Jump to content

Class


Andy-H

Recommended Posts

This class works fine; I was just wondering if I am using it right and if there is any way to operate on multiple queries with one instance of the class.  ???

 

<?php
class db
{
var $host;
var $user;
var $pass;
var $DB;
function db($host = 'localhost', $user = '*******', $pass = '*******', $DB = '*******')
{
  $conn = mysql_connect($host, $user, $pass);
  $db   = mysql_select_db($DB, $conn);
}
function query($str)
{
  $this->query = mysql_query($str)or die('Query failed on line ' . __LINE__);
}
function num()
{
  return mysql_num_rows($this->query);
}
function fetch($type = 'row')
{
  return mysql_fetch_row($this->query);
}
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/140291-class/
Share on other sites

Is this what you mean?

 

$db = new db;
$sales=$db->query('SELECT * FROM sales');

while ($row = mysql_fetch_assoc($sales)) {
// Do something
}

// Call $result whatever you want
$staff=$db->query('SELECT * FROM staff');

while ($row = mysql_fetch_assoc($staff)) {
// Do something
}

 

Link to comment
https://forums.phpfreaks.com/topic/140291-class/#findComment-734066
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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