View Single Post
Old 01-03-2009, 08:00 AM   #1 (permalink)
9three
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