TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-03-2009, 08:00 AM   #1 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default Messing around with OOP

I'm just messing around with OOP since I've never used it before. I'm able to make a connection, select my database, and query it. I'm having a problem when I want to create an array:

mysql.class.php
PHP Code:
  public function query($query)
  {
    
$this->query mysql_query($query$this->link);
    if (!
$this->query)
    {
      Throw New 
Exception('Unable to query');
    }
  }

  public function 
fetcharray()
  {
    
$this->fetch $this->query();
    
$return = array();
    while (
$field mysql_fetch_array($this->fetch))
    {
      
$return[] = $field;
    }
    return 
$return;
  } 
When I put the code to work this is what it looks like:

index.php
PHP Code:
$connection = new mysql();
$connection->connect('localhost''root''');
$connection->select('9three');
$query "SELECT * FROM clients";
$connection->query($query);
$connection->fetcharray(); 
I'm just trying to pull whatever information is in the table. But its giving me an error:

Warning: Missing argument 1 for mysql::query(), called in C:\Users\9three\Desktop\Server\htdocs\9three\libra ry\9three\mysql.class.php on line 36 and defined in C:\Users\9three\Desktop\Server\htdocs\9three\libra ry\9three\mysql.class.php on line 25

Fatal error: Uncaught exception 'Exception' with message 'Unable to query' in C:\Users\9three\Desktop\Server\htdocs\9three\libra ry\9three\mysql.class.php:30 Stack trace: #0 C:\Users\9three\Desktop\Server\htdocs\9three\libra ry\9three\mysql.class.php(36): mysql->query() #1 C:\Users\9three\Desktop\Server\htdocs\9three\index 2.php(15): mysql->fetcharray() #2 {main} thrown in C:\Users\9three\Desktop\Server\htdocs\9three\libra ry\9three\mysql.class.php on line 30

I can do it through the procedural but it defeats the purpose of learning
9three is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:27 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design