473,582 Members | 3,040 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use the db class to other class....... i cannot display the records.

1 New Member
Expand|Select|Wrap|Line Numbers
  2. <?PHP
  4. class db
  5. {
  6.      private $hostname;
  7.      private $username;
  8.      private $password;
  9.      private $database;
  10.      private $connect;
  11.      private $select_db;
  12.      public  $dbSql;
  14.      public function db()
  15.      {
  16.           $this->hostname = "localhost";
  17.           $this->username = "root";
  18.           $this->password = "";
  19.           $this->database = "mydb";
  20.      }
  22.      public function open_connection()
  23.      {
  24.           try
  25.           {
  26.                $this->connect = mysql_connect($this->hostname,$this->username,$this->password);
  27.                $this->select_db = mysql_select_db($this->database);
  28.           }
  29.           catch(exception $e)
  30.           {
  31.                return $e;
  32.           }
  33.      }
  35.      public function close_connection()
  36.      {
  37.           try
  38.           {
  39.                mysql_close($this->connect);
  40.           }
  41.           catch(exception $e)
  42.           {
  43.                return $e;
  44.           }
  45.      }
  46. }
  48. ?>
  50. <?php
  51. //Class to use the db class....
  52. include('db.php');
  54. class usr{
  56.   private $mydb;
  58.   $mydb = new db;//::open_connection();
  60.   public function users_query()
  61.      {
  62.           try
  63.           {
  64.                //$this->$mydb->open_connection();
  65.                $mydb->dbSql = mysql_query("SELECT * FROM users");
  66.           }
  67.           catch(exception $e)
  68.           {
  69.                return $e;
  70.           }
  71.           $mydb->close_connection();
  72.           return $mydb->dbSql;
  73.  }
  75. }
  76. ?>
  80. <?php
  82.      //DISPLAY USERS***************************
  83.         include('..//controller/getrecord.php');
  84.         $grec=new grecord();
  85.         $grec->display_users();
  86.      //****************************************     
  87.     ?>
May 3 '11 #1
1 1456
8,658 Recognized Expert Moderator Expert
line #58: syntax error! a class property can only be initialised with a scalar or array, never with a function call or object initialisation.

class db: the outdated mysql extension will never throw an Exception, the only DB system that does that (which I know) is PDO.

class usr: there’s no constructor or dependency injector to get the db object.

if you want to dabble with databases and OOP, I strongly advise you to use PDO or MySQLi as they are already classes and as such more suited to be used in OOP.
May 3 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Dennis C. Drumm | last post by:
Is there a way with C# to allow one class access to a method or field of another class, without making that method or field visible to all other classes, as would be the case when making the method or field public? Thanks, Dennis
by: yoshitha | last post by:
hi, i want to display records in datagrid. strtestids() is a string array. it contains some testids. based on these ids i've to fill the datagrid. i wrote code like this
by: Tony | last post by:
vs 2002 - vb - access 2002 - xp - web forms I want to display records, one at a time. I have about 25 fields to display. I've created SQL and retrieved records. I placed data in 25 separate dropdown list. (made them invisible on form) each time they pick next I add 1 and do something like this for each field CurrentRecord += 1 (test for...
by: Kai Zhang | last post by:
I am trying to display some database records in datagrid using dataset. the records need to be displayed are couple of thousands, but the records in database that the SQL query needs to exam are more than 70 thousand, and it is really slow to get the dataset ready to populate the datagrid. I am sure there are solutions on this issue, but I...
by: hameeduddinasim | last post by:
Hi i have 2 button on a web page(index.aspx) and both the button have the same code i.e. response.redirect("index.aspx?var=c") but when i click one button it is refreshing the page and the URL is changed to "index.aspx?var=c" which i need but when i click other button it displays ("Internet Explorer cannot display the webpage") kindly...
by: tjc0ol | last post by:
Hi guys, I'm a newbie of this stuffs, We had a small office network (1 Windows 2K - Server) and (3 Windows XP - Client). I am testing to 1 PC (Windows 2K) installed with Licensed Wingate 6.2.2 - i.e. my Server and 1 Windows XP as my client. The Server which is Windows 2K has 2 NICs on it, One is connected to the Modem - Gilat...
by: dorandoran | last post by:
How do I display records using object oriented method? All I have the link to their api help http://www.e-topco.com/oa/oa_help/OpenAir_SOAP.htm and few example. I am want display all the active projects when user click on get active projects on windows form (vb.net). Please suggest. I have been struggling on this for past 11 days. ...
by: eschneider | last post by:
I get the following error when trying to browse the .asmx. I get the same thing when trying to add a reference. using .NET 2.0 There is no error message. Any ideas? Thanks,
by: jawad malik | last post by:
I want that each time i execute query it display records in a way that the top record will be positioned last and so on. First time when i executed query it will display like this name A B C D second time name B
by: Rahul Metha | last post by:
o Select table from drop down list. o Display records in Grid – Display all records belong to table in grid. o Table Fields – This section will have all the fields which are belongs to table.
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.