PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] Fatal error: Class 'medoo' not found

 January 20, 2022     composer-php, medoo, php, slim, slim-2     No comments   

Issue

I am using slim framework 2 with medoo via composer, i am making singleton for medoo but when i call the medoo class to configure my db info, so it gives me the fatal error like below

Fatal error: Class 'medoo' not found in C:\xampp\htdocs\school\s.php on line 5

below is my s.php file

<?php
  require 'vendor/autoload.php';
  $app = new\Slim\Slim();
    $app->container->singleton('test',function () use ($app) {
      return new medoo([
        'database_type' =>'mysql',
        'database_name' =>'mydb',
        'server'=> 'localhost',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
        'option' => [
          PDO::ATTR_CASE=>PDO::CASE_NATURAL
        ]
      ]);
    });

    $app->get('/', function () use($app) {
      echo "<center><b><a href='#' target='_blank' >WELCOME TO TESTING PAGE</a></b></center>";
      $sth = $app->test->insert("t", ["id" =>1, "name" => "dsfdsf"]);
      var_dump($sth);
    });

  $app->run();
?> 

If i check the composer.json file then i find slim and medoo both are there, i am not getting why this fatal error is coming please help me


Solution

Two things:

  • you need to import the class
  • your class name should be case-sensitive

That is:

<?php

use Medoo\Medoo;

require 'vendor/autoload.php';

$app = new \Slim\Slim();

$app->container->singleton('test',function () use ($app) {
    return new Medoo([
        // ...
    ]);
});

For reference, see:

  • http://php.net/manual/en/language.namespaces.php
  • https://github.com/catfan/Medoo/tree/v1.4.5


Answered By - localheinz
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing