Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Database namespace error..?
  • Hi all. Apologies in advance for the formatting - I can't seem to lay the post out nicely using this forum. I've just started trying to use the Fuel framework. I like the look of it, but for some reason I just can't get a simple database query to work. I have 'activerecord' as a package in my app/config/config.php I used the following command to generate code using oil:
    php oil g scaffold artist name:varchar[150] country_id:tinyint[3]
    

    After this, I navigate to my local URL ([url=http://localhost/artists/]http://localhost/artists/[/url]) and I'm presented with this:
    Fatal error: Call to undefined function Fuel\Core\mysql_connect() in <snip>/mixdb/fuel/core/classes/database/mysql.php on line 67
    

    I have also tried without ActiveRecord and accessing the DB object directly, in a separate controller:
    <?php
    
    class Controller_Artist extends Controller &#123;
    
     public function action_index()
     {
      $data['list'] = $this->get_list();
      $this->render('welcome/index', $data);
     }
    
     public function get_list()
        {
      $users = DB::select('*') ->from('artist')->as_object()->execute();
      var_dump($users);
        }
    }
    

    I'm still getting the same error. It's driving me a little batty, since I'm sure it must be something simple that I haven't done / am doing wrong. Please, correct my (potential) stupidity / naivety / whatever and tell me where I've gone wrong? Thanks in advance,
    Dwight.
  • PHP native functions should be taken from the root namespace, with or without backslash prefix. That it causes this error would suggest you got a PHP version that is compiled without the mysql plugin that has the functions prefixed with mysql_, are you able to use mysql natively? Have you tried it outside Fuel? A solution might be to use the PDO driver instead. You can see an example of the PDO config for a sqlite DB here. And there's docs on mysql DSN on php.net.
  • Ah, you're exactly right - I compiled with mysqli and not mysql :) Thank you. PDO is generating another error, but it seems I haven't added in PDO_MYSQL to my build, either. I'll put this down to silly configuration mistakes, try again tomorrow with a fresh build and let you know how I go! Thanks for the prompt reply.
  • Thanks again for your help mate, I recompiled PHP this morning with mysql + mysqli and it's working fine now. Another issue I'm having though - can I somehow prevent Fuel / ActiveRecord from turning my table names into plurals? There must be a way I can control my own table names without an 's' being tacked onto the end all the time? Thanks,
    Dwight.
  • Hmm, looks like this is an ActiveRecord thing, and I'm guessing there's no way to turn it off :)
  • AR is currently being rewritten, one of the reasons being that it lacks a bit in how much can be configured. The table name however can already be configured, just add a property in your model definition:
    class Model_Example extends ActiveRecord\Model {
        protected $table_name = 'example_table';
    }
    
  • Can we also have transactions?
    They can be optional with a way to enable/disable them in a config or something.
  • If transactions are going to be supported they'd be in the querybuilder and support for them in a new ORM package would be through that QB. Having said that, this is mostly Dan's area so you'll have to ask him to get a more definitive answer.
  • Great, that's exactly what I need, thank you. Good to hear it will be more configurable in the future, too. Thanks for all your work!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion