Uncaught SoapFault exception: [SOAP-ENV:Server] Function 'X' doesn't exist - php

I'm trying to setup a web service without wsdl (for the moment) but is not working.
I have a file called "Operaciones.php" with the following code:
<?php
namespace ClasesT6;
use PDO, PDOException;
class Operaciones extends Conexion {
public function __construct()
{
parent::__construct();
}
function getPVP($id) {
$pvp = null;
$consulta = " SELECT pvp FROM productos WHERE id='$id' ";
$stmt = $this->conexion->prepare($consulta);
try {
$stmt->execute();
if($stmt) {
$row = $stmt->fetch();
$pvp = $row['pvp'];
}
} catch (PDOException $ex) {
die("Error al recuperar el pvp del producto indicado: " . $ex->getMessage());
}
return $pvp;
}
function getStock($idproducto, $idtienda) {
$stock = null;
$consulta = " SELECT unidades FROM stocks WHERE producto='$idproducto' AND tienda='$idtienda' ";
$stmt = $this->conexion->prepare($consulta);
try {
$stmt->execute();
if($stmt) {
$row = $stmt->fetch();
$stock = $row['unidades'];
}
} catch (PDOException $ex) {
die("Error al recuperar el stock del producto indicado en la tienda indicada: " . $ex->getMessage());
}
return $stock;
}
function getFamilias() {
$familiasCod = array();
$consulta = " SELECT * FROM familias ";
$stmt = $this->conexion->prepare($consulta);
try {
$stmt->execute();
if($stmt) {
$row = $stmt->fetch();
while ($row != null) {
$familiasCod[] = "{$row['cod']}";
$row = $stmt->fetch();
}
}
} catch (PDOException $ex) {
die("Error al recuperar el código de las familias: " . $ex->getMessage());
}
return $familiasCod;
}
function getProductosFamilia($cod) {
$productosFamiliaIds = array();
$consulta = " SELECT id FROM productos WHERE familia='".$cod."' ";
$stmt = $this->conexion->prepare($consulta);
try {
$stmt->execute();
if($stmt) {
$row = $stmt->fetch();
while ($row != null) {
$productosFamiliaIds[] = "{$row['id']}";
$row = $stmt->fetch();
}
}
} catch (PDOException $ex) {
die("Error al recuperar el id de los productos de la familia indicada: " . $ex->getMessage());
}
return $productosFamiliaIds;
}
}
?>
Then I have the file "service.php" with the following code:
<?php
require '../vendor/autoload.php';
$uri = 'http://localhost/archivos/FP/DWES/tarea6/servidorSoap';
$parametros = ['uri'=>$uri];
try {
$server = new SoapServer(NULL, $parametros);
$server->setClass('Operaciones');
$server->handle();
} catch (SoapFault $f) {
die("error en server: " . $f->getMessage());
}
?>
And then I have the file "cliente.php" with the following code:
<?php
require '../vendor/autoload.php';
$url = 'http://localhost/archivos/FP/DWES/tarea6/servidorSoap/servicio.php';
$uri = 'http://localhost/archivos/FP/DWES/tarea6/servidorSoap';
header('Content-Type: text/html; charset=UTF-8');
try {
$cliente = new SoapClient(null, ['location' => $url, 'uri' => $uri, 'trace'=>true]);
} catch (SoapFault $ex) {
echo "Error: ".$ex->getMessage();
}
$paramPVP = ['id' => "1"];
$getPVP = $cliente->__soapCall('getPVP', $paramPVP);
?>
When I open client.php on my localhost I get this error:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Function 'getPVP' doesn't exist in /Applications/XAMPP/xamppfiles/htdocs/files/FP/DWES/task6/public/client.php:17 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/archivos/FP/DWES/tarea6/public/cliente.php(17): SoapClient->__soapCall('getPVP', Array) #1 {main} thrown in /Applications/XAMPP /xamppfiles/htdocs/archivos/FP/DWES/tarea6/public/cliente.php on line 17
I've followed the instructions of the notes from my course to make service.php and cliente.php but it is not working and I don't know how to fix it.
Many thanks in advance for your solution suggestions

Related

Uncaught ArgumentCountError: Too few arguments to function delete(), 4 and exactly 5 expected but i have 5 argument

I can't understand my mistake ' Too few arguments to function delete(), 4 and exactly 5 expected but i have 5 argument ! I can't find a solution
// Permet delete un article
function delete($title, $content, $posted, $post_id, $id)
{
// connexion a la bd
global $db;
// tableau pour la requête
$e = [
'id' => $id,
'id' => $post_id
];
$sql = "DELETE FROM posts WHERE id=:id";
$datas = array(':id' => $id);
try {
$req = $db->prepare($sql);
$res = $req->execute($datas);
} catch (Exception $e) {
echo " Erreur : " . $e->getMessage();
}
$sql = "DELETE FROM comments WHERE post_id=:id";
$datas = array(':id' => $id);
try {
$req = $db->prepare($sql);
$res = $req->execute($datas);
} catch (Exception $e) {
echo " Erreur : " . $e->getMessage();
}
return !empty($res) ? $res : false;
return !empty($res) ? $res : false;
}
I think the problem is with second delete(delete from comments) because the first request works but not the second.
Here is the function called
if(isset($_POST['supri'])) {
$title = htmlspecialchars(trim($_POST['title']));
$content = htmlspecialchars(trim($_POST['content']));
$post_id = htmlspecialchars(trim($_COMMENTS['post_id']));
$posted = isset($_POST['public']) ? "1" : "0";
$errors = [];
delete($title,$content,$posted,$post_id,$id);

PHP 7.x SQLITE3 PDO - is the execute() closing the PDO connection?

I have this code that works weird with SQLITE3 , since the same code with MYSQL works fine
The issue is the line commented with "ISSUE" at line #31, because with MYSQL/MariaDB that "re connection" is NOT needed
Now I better explain
If the IF routine is not entered, I have NO error
If the IF routine is processed, line #34 throws
Uncaught Error: Call to undefined method PDOStatement::prepare()
like if the $PDO-execute(); inside the IF is destroying the PDO istance
You may say, well, no problem, now you have fixed it ... yes, but I'd like to understand why this happen.
Also portability is a point. If this is PDO ... except for the connection, the rest of the script should work and moved among various supported PDO DBs
Thank you if you kindly hint what is the reason and what is it
<?php
// Create or open a database file
$PDO = new PDO('sqlite:myDatabase.sqlite3');
if( isset($_POST['NoteUpdateText']) && !empty(trim($_POST['NoteUpdateText'])) ){
//$testo = $_POST['NoteUpdateText'];
try {
$PDO = $PDO->prepare('UPDATE ajax SET testo = :testo WHERE id = :id');
$PDO->bindValue(':testo', $_POST['NoteUpdateText']);
$PDO->bindValue(':id', 1);
$PDO->execute();
// echo a message to say the UPDATE succeeded
//echo $stmt->rowCount() . " records UPDATED successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
}
// In EVERY case, load the actual DB record and return it to javascript
$PDO = new PDO('sqlite:myDatabase.sqlite3'); // --- ISSUE, theoretically this is already opened at line #3 ---
try {
$PDO = $PDO->prepare('SELECT testo FROM ajax WHERE id=1 LIMIT 1');
$PDO->execute();
$row = $PDO->fetch();
//var_dump($row);
echo $row["testo"];
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
?>
FIXED CODE
<?php
//include 'db-con2.php';
// table: ajax
// col: testo
// Create or open a database file
$PDO = new PDO('sqlite:myDatabase.sqlite3');
if( isset($_POST['NoteUpdateText']) && !empty(trim($_POST['NoteUpdateText'])) ){
//$testo = $_POST['NoteUpdateText'];
try {
$statement = $PDO->prepare('UPDATE ajax SET testo = :testo WHERE id = :id');
$statement->bindValue(':testo', $_POST['NoteUpdateText']);
$statement->bindValue(':id', 1);
$statement->execute();
// echo a message to say the UPDATE succeeded
//echo $stmt->rowCount() . " records UPDATED successfully";
}
catch(PDOException $e)
{
echo $sql . "<br> - IF -" . $e->getMessage();
}
}
// carica da DB in ogni caso per caricare il P col testo realmente in DB
//$PDO = new PDO('sqlite:myDatabase.sqlite3');
try {
$statement = $PDO->prepare('SELECT testo FROM ajax WHERE id=1 LIMIT 1');
$statement->execute();
$row = $statement->fetch();
//var_dump($row);
echo $row["testo"];
}
catch(PDOException $e)
{
echo $sql . "<br> - NORMALE - " . $e->getMessage();
}
?>
Why would you override $PDO variable ?
$pdo = new PDO('sqlite:myDatabase.sqlite3');
if( isset($_POST['NoteUpdateText']) && !empty(trim($_POST['NoteUpdateText'])) ){
//$testo = $_POST['NoteUpdateText'];
try {
$stmt = $PDO->prepare('UPDATE ajax SET testo = :testo WHERE id = :id');
if ($stmt->execute(array(':testo'=>$_POST['NoteUpdateText'], ':id' => 1)))
{
// echo a message to say the UPDATE succeeded
//echo $stmt->rowCount() . " records UPDATED successfully";
} else {
// There's error processing updates
// debug
print_r($stmt->errorInfo());
}
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
}
// In EVERY case, load the actual DB record and return it to javascript
// There's no need to redeclare $PDO
// $PDO = new PDO('sqlite:myDatabase.sqlite3'); // --- ISSUE, theoretically this is already opened at line #3 ---
try {
$stmt = $pdo->prepare("SELECT testo FROM ajax WHERE id=1 LIMIT 1"); // line #34
$stmt->execute();
$row = $stmt->fetch();
//var_dump($row);
echo $row["testo"];
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}

Error Request to prepare SELECT type on PHP 5.3

I am trying to make a preparation type Select but it does not work and I can not see where the error is.
Thank you for your help and your explanations :)
try{
$sql = " SELECT * FROM `eq_base`";
$sql .= " WHERE `eq_base`.`DateAchat` >= $sel_date or `eq_base`.`DateAchat` = \"0000-00-00\" ";
if (!("$sel_type"==99999)) { $sql .= " AND `eq_base`.`Type` = :sel_type"; }
if (!("$sel_etat"==99999)) { $sql .= " AND `eq_base`.`Etat` = sel_etat"; }
if (!empty("$sel_modele")) { $sql .= " AND `eq_base`.`Modele` LIKE %:sel_modele% "; }
if (!empty("$sel_fournisseur")) { $sql .= " AND `eq_base`.`Fournisseur` LIKE %:sel_fournisseur% "; }
$sql .= " ORDER by `eq_base`.`cle`";
var_dump($sql);
$db = Database::getInstance();
$req = $db->prepare($sql);
$req->bindValue(':sel_date',$sel_date);
$req->bindValue(':sel_type',$sel_type);
$req->bindValue(':sel_etat',$sel_etat);
$req->bindValue(':sel_modele',$sel_modele);
$req->bindValue(':sel_fournisseur',$sel_fournisseur);
$req->execute();
$temp = $req->fetchAll();
//$updated = $req->rowCount();
}catch (Exception $e) {
error_log($e);
throw new Exception("Une erreur s'est produite lors de la création de l'équipement informatique.");
}
}
First of all you had some syntax mistakes like double quoting the variables inside the if statement if (!("$sel_type"==99999)) and forgeting to put : before sel_etat.
Secondly you are creating the query dynamicaly but you are binding all the variables regardless. You should make the same checks as when you build your query to make sure you only bind variables that exist in your query.
Something like this should work
try{
$sql = " SELECT * FROM `eq_base`";
$sql .= " WHERE (`eq_base`.`DateAchat` >= ':sel_date' or `eq_base`.`DateAchat` = '0000-00-00') ";
if (($sel_type!=99999)) { $sql .= " AND (`eq_base`.`Type` = ':sel_type')"; }
if (($sel_etat!=99999)) { $sql .= " AND (`eq_base`.`Etat` = ':sel_etat')"; }
if (!empty($sel_modele)) { $sql .= " AND (`eq_base`.`Modele` LIKE '%:sel_modele%')"; }
if (!empty($sel_fournisseur)) { $sql .= " AND (`eq_base`.`Fournisseur` LIKE '%:sel_fournisseur%')"; }
$sql .= " ORDER by `eq_base`.`cle`";
var_dump($sql);
$db = Database::getInstance();
$req = $db->prepare($sql);
$req->bindValue(':sel_date',$sel_date);
if (($sel_type!=99999)){
$req->bindValue(':sel_type',$sel_type);
}
if (($sel_etat!=99999)) {
$req->bindValue(':sel_etat',$sel_etat);
}
if (!empty($sel_modele)){
$req->bindValue(':sel_modele',$sel_modele);
}
if (!empty($sel_fournisseur)){
$req->bindValue(':sel_fournisseur',$sel_fournisseur);
}
$req->execute();
$temp = $req->fetchAll();
//$updated = $req->rowCount();
}
catch (Exception $e) {
error_log($e);
throw new Exception("Une erreur s'est produite lors de la création de l'équipement informatique.");
}
Yes Dimitris my code is below and my log error also
try{
$sql = " SELECT * FROM `eq_base`";
$sql .= " (WHERE `eq_base`.`DateAchat` >= :sel_date or `eq_base`.`DateAchat` = \"0000-00-00\") ";
if ($sel_type!==99999) { $sql .= " AND `eq_base`.`Type` = :sel_type"; }
if ($sel_etat!==99999) { $sql .= " AND `eq_base`.`Etat` = :sel_etat"; }
if (!(empty($sel_modele))) { $sql .= " AND `eq_base`.`Modele` LIKE :sel_modele"; }
if (!(empty($sel_fournisseur))) { $sql .= " AND `eq_base`.`Fournisseur` LIKE :sel_fournisseur"; }
$sql .= " ORDER by `eq_base`.`cle`";
$db = Database::getInstance();
$req = $db->prepare($sql);
var_dump($req);
$req->bindValue('sel_date', $sel_date);
if($sel_type !==99999){
$req->bindValue('sel_type',$sel_type);
}
if($sel_etat !==99999){
$req->bindValue('sel_etat',$sel_etat);
}
if($sel_modele !==99999){
$req->bindValue('sel_modele','%'.$sel_modele.'%');
}
if($sel_fournisseur !==99999){
$req->bindValue('sel_fournisseur','%'.$sel_fournisseur.'%');
}
$req-execute();
$resultat = $req->fetchAll();
}catch (Exception $e) {
error_log($e);
throw new Exception("Une erreur s'est produite lors de la création de l'équipement informatique.");
}
}
LOG ERROR IS : PHP Fatal error: Call to undefined function execute()

SQL error that i could not figure it out

This is the code:
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=mydatabase;charset=utf8', 'root', '',array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$req = $bdd->prepare('SELECT nom FROM jeux_video WHERE possesseur = ?');
$req->execute(array($_GET['possesseur']));
while($data = $req->fetch()){
echo $data['nom'].'<br/>';
}
$req->closeCursor();
?>
and this is the error:
Notice: Undefined index: possesseur in /opt/lampp/htdocs/openclassroom/index.php on line 12
The variable "possesseur" is not passed in the URL like that
script.php?possesseur=TEST
It is not a Mysql error, it is a PHP notice
$req->execute(array($_GET['possesseur']));
You're not checking if $_GET['possesseur'] exists. Add an if clause in it:
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=mydatabase;charset=utf8', 'root', '',array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
if (isset($_GET['possesseur'])) {
$req = $bdd->prepare('SELECT nom FROM jeux_video WHERE possesseur = ?');
$req->execute(array($_GET['possesseur']));
while($data = $req->fetch()){
echo $data['nom'].'<br/>';
}
$req->closeCursor();
}

Undefined index:session LOOP NOT WORKING php, pdo oop

I make users online page using PHP - OOP - PDO
include_once '../database.php';
$db = new database();
$getRows = $db->getRows('select * from visitors_online');
$gr = $db->rowCount();
$online = '';
$getRow = $db->getRow('select * from user_online');
$gr2 = $db->rowCount();
if(!empty($gr2)) {
try {
while ($getR = $getRow){
$getRow = $db->getRow('select * from users where id = ?',[$getR['session']]);
echo ', &nbsp '.$getRow['username'].' &nbsp ';
}
} catch (PDOException $e) {
die('Error :'. $e->getMessage());
}
$total = $gr + $gr2;
The problems is:
* Not show any users except Admin, also I got this :
ONLINE
admin
Notice: Undefined index: session in /Applications/MAMP/htdocs/baws/admin/online.php on line 56
,
.Users = 0 ,Member = 2 , Register = 2
Who is online list
Here is the function from Database class
// Get row by id, username, or email etc..
public function getRow($query, $para = []){
try {
$this->stmt = $this->datab->prepare($query);
$this->stmt->execute($para);
return $this->stmt->fetch();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
Any Help
Thanks
I tried to simplify a bit your code as I do not know your class details and it s messy.
The problem is you are not binding stuff properly neither fetching them properly too. Also, you are preparing the second query, each time you loop inside the query 1 results , that is useless. prepare both (withyour class or not) and just bind and execute.
$stmt1 = $db->prepare('select * from user_online where id= ?');
$result1 = getRows($stmt1, "1");
$gr1 = $db->rowCount();
if (!empty($gr1)) {
$stmt2 = $db->prepare('select * from users where id = ?');
foreach ($result1 as $key1 => $h1) {
$stmt2->bindParam(1, $h1['session'], PDO::PARAM_INT);
$stmt2->execute();
$result2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
if (count($result2) !== 0) {
foreach ($result2 as $key2 => $r2) {
echo ', &nbsp ' . $r2['username'] . ' &nbsp ';
}
}
}
}
function getRow($query, $para) {
$stmt1->bindParam(1, $para, PDO::PARAM_INT);
try {
$stmt1->execute($para);
$result1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
return $result1;
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
Please find the database class here
class database {
public $isConn;
protected $datab;
private $stmt;
public function __construct() {
$this->connect();
}
// connect to database
private function connect(){
$host = 'localhost';
$db = 'baws';
$user = 'root';
$pass = 'root';
$option = [];
$this->isConn = TRUE;
try {
$this->datab = new PDO('mysql:host='.$host.';dbname='.$db.';charset=utf8', $user, $pass, $option);
$this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->datab->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<h3>Not connected</h3>' . $e->getMessage();
}
}
// Disconnected from database
private function disconnect(){
$this->isConn = NULL;
$this->datab = FALSE;
}
//insert to database
public function insertRow($query, $para = []){
try {
$this->stmt = $this->datab->prepare($query);
$this->stmt->execute($para);
return TRUE;
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
//update row to database
public function updateRow($query, $para = []){
$this->insertRow($query, $para);
}
//Delete row from database
public function deleteRow($query, $para = []){
$this->insertRow($query, $para);
}
// Get row by id, username, or email etc..
public function getRow($query, $para = []){
try {
$this->stmt = $this->datab->prepare($query);
$this->stmt->execute($para);
return $this->stmt->fetch();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
}
online.php Page
ob_start();
echo "ONLINE <br>";
include_once '../database.php';
$db = new database();
try {
$session=$_COOKIE['id'];
$time=time();
$time_check=$time-300; //SET TIME 10 Minute
$getRow = $db->getRow("SELECT * FROM user_online WHERE session = ?", [$session]);
$count =$db->rowCount($getRow);
if($count == '0'){
$insertRow = $db->insertRow("INSERT INTO user_online(session, time)VALUES(? , ?)",[$session, $time ]);
}
elseif($count != '0'){
$updateRow = $db->updateRow("UPDATE user_online SET time = ? WHERE session = ?", [$time, $session]);
}else{
$deleteRow = $db->deleteRow("DELETE FROM user_online WHERE time < ? ", [$time_check]);
}
} catch (PDOException $e) {
die('Error :'. $e->getMessage());
}
try {
$ip=$_SERVER['REMOTE_ADDR'];
$session=$ip;
$time=time();
$time_check=$time-300; //SET TIME 10 Minute
$deleteRow = $db->deleteRow("DELETE FROM visitors_online WHERE time < ? ", [$time_check]);
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
$getRows = $db->getRows('select * from visitors_online');
$gr = $db->rowCount();
$online = '';
$getRow = $db->getRow('select * from user_online');
$gr2 = $db->rowCount();
if(!empty($gr2)) {
try {
while ($getR = $getRow){
$getRow = $db->getRow('select * from users where id = ?',[$getR['session']]);
echo ', &nbsp '.$getRow['username'].' &nbsp ';
}
} catch (PDOException $e) {
die('Error :'. $e->getMessage());
}
$total = $gr + $gr2;
} //end

Categories