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
  1.  
  2. <?PHP
  3. //THIS IS MY DB CLASS CONNECTION
  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;
  13.  
  14.      public function db()
  15.      {
  16.           $this->hostname = "localhost";
  17.           $this->username = "root";
  18.           $this->password = "";
  19.           $this->database = "mydb";
  20.      }
  21.  
  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.      }
  34.  
  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. }
  47.  
  48. ?>
  49.  
  50. <?php
  51. //Class to use the db class....
  52. include('db.php');
  53.  
  54. class usr{
  55.  
  56.   private $mydb;
  57.  
  58.   $mydb = new db;//::open_connection();
  59.  
  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.  }
  74.  
  75. }
  76. ?>
  77.  
  78.  
  79.  
  80. <?php
  81. //AND MY OTHER CODES TO DISPLAY THE RECORDS...
  82.      //DISPLAY USERS***************************
  83.         include('..//controller/getrecord.php');
  84.         $grec=new grecord();
  85.         $grec->display_users();
  86.      //****************************************     
  87.     ?>
  88.  
  89.  
May 3 '11 #1
1 1456
Dormilich
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

4
4623
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
2
1469
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
0
1318
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...
3
5396
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...
1
2118
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...
0
2761
tjc0ol
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...
5
1266
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. ...
4
4413
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,
8
3387
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
0
951
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.
0
7809
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...
0
8159
Oralloy
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. ...
0
8312
jinu1996
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...
0
8183
tracyyun
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...
1
5685
isladogs
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...
0
3809
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...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2312
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
1
1413
muto222
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.