Tengo una base de datos en MySQLWorkBench
.
Este es mi archivo connection.php
<?php
class MySqlConnection
{
//get connection
public static function getConnection()
{
//read config
$data = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/sasy/config/connection.json');
$config = json_decode($data, true);
//parameters
if (isset($config['server']))
$server = $config['server'];
else {
echo 'Configuration error : MySql Server name not found';
die;
}
if (isset($config['user']))
$user = $config['user'];
else {
echo 'Configuration error : User name not found';
die;
}
if (isset($config['password']))
$password = $config['password'];
else {
echo 'Configuration error : Password not found';
die;
}
if (isset($config['database']))
$database = $config['database'];
else {
echo 'Configuration error : Database name not found';
die;
}
//open connection
$connection = mysqli_connect($server, $user, $password, $database);
//error in connection
if ($connection === false) {
echo 'Could not connect to MySql';
die;
}
//character set
$connection->set_charset('utf8');
//return connection object
return $connection;
}
}
?>
Y adema tengo este archivo con nombre connection.js
{
"server" : "localhost",
"database" : "sasy",
"user" : "root",
"password" : ""
}
Tengo la siguiente Api
:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
// require_once('connection.php');
require_once('../models/connection.php');
if($_SERVER['REQUEST_METHOD']=='GET')
{
if(isset($_GET['email_user']) && isset($_GET['password_user']))
{
$email_user=$_GET["email_user"];
$password_user=$_GET["password_user"];
$connection = new MySqlConnection();
$query = 'SELECT id_user, email_user,password_user,idCode from users where email_user = ? AND password_user= ?';
$result=$connection->executeQuery($query, array($email_user,$password_user));
if ($result>0)
{
$user = json_encode(array(
'id_user' => $result[0][0],
'email_user' => $result[0][1],
'password_user' => $result[0][2],
'idCode' => $result[0][3]
));
echo json_encode(array(
'status' => 0,
'user' => json_decode($user)
));
}//if
else
{
echo json_encode(array(
'status' => 1,
'errorMessage' => 'user not found'
));
}//else
}
} //CIERRA IF
?>
Al intentar obtener los datos poniendo parametros en postman, me sale lo siguiente:
Fatal error: Call to undefined method MySqlConnection::executeQuery() in C:\xampp\htdocs\sasy\apis\login.php on line 17
Linea 17:
$result=$connection->executeQuery($query, array($email_user,$password_user));
¿Cual puede ser mi error?
executeQuery
por este otroexecute();
?