Closed rajkumarpb closed 4 years ago
There's not enough in your code to determine the issue.
I would suggest: 1) Try routing without database connection 2) Try reviewing PHP error logs for hints 3) Use xdebug to debug
If these fail, please share more code and ideally a link to your code online.
My guess is that it is a database init/connection issue.
Full Code here: Before using Medoo I was using PDO and it was working fine. Only with Medoo I'm getting 500 Internal Server Error.
<?php
require 'vendor/autoload.php';
require 'Medoo.php';
// Using Medoo namespace
use Medoo\Medoo;
$medoo_Config = [
// required
'database_type' => 'mysql',
'database_name' => 'xxxx',
'server' => 'localhost',
'username' => 'yyyy',
'password' => 'zzzz',
// Enable logging
"logging" => true,
];
Flight::register( "db", new Medoo( $medoo_Config ), [ $medoo_Config ] );
/* Flight::register('db', 'PDO', array('mysql:host=localhost;port=3306;dbname=xxxxx', 'yyyy', 'zzzz'), function($db) {
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
}); */
Flight::route('GET /getclients', function(){
$conn = Flight::db();
/*$conn = Flight::db();
$idata = [];
$SQL = "SELECT c.*, s.state_name,s.state_id, cn.country_name FROM client c, state s, country cn WHERE c.client_state = s.state_id AND c.client_country = cn.country_id";
$dbdata = $conn->query($SQL);
if(!empty($dbdata)) {
foreach($dbdata as $row) {
array_push($idata, $row);
}
}
echo json_encode($idata);*/
$data = $conn->select("client" , [
"[>]state" => ["client_state" => "state_id"],
"[>]country" => ["client_country" => "country_id"],
],[]);
echo json_encode($data);
});
Flight::start();
?>
If someone needed. Line 19 has to be like this:
Flight::register("db", 'Medoo\Medoo', [ $medoo_Config ]);
FWIW, I'm putting this in the framework in the next little bit. Just a simplified Pdo_Wrapper https://github.com/flightphp/core/compare/master...database-class
Hi @mikecao
As per #348 , I have registered the Medoo framework class with flightphp. But not able to get any data and I'm getting 500 error. Can you please tell me whats wrong with the code?