Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> PDO::PARAM_INPUT_OUTPUT, Problemy z parametrem out procedury mysql
pdusp
post 19.08.2020, 15:04:45
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 19.08.2020

Ostrzeżenie: (0%)
-----


witam,
sam nie moge rozwiązać problemu dlatego postanowiłem się zwrócić do Was o pomoc.

mam procedure, które zwraca tekst w zmiennej out:

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_returns_string`( out _txt varchar(50))
BEGIN
set _txt ='berger never dies';
END

i to działa bo można sobie uruchomić:
set @_txt = '0';
call test.sp_returns_string(@_txt);
select @_txt;


nie działa juz przez PHP, zmienna wyjściowa jest pusta...
co robię źle?

$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');

$value2 = '123456hhh';
$stmt = $db->prepare("call sp_returns_string(?) ;"); // the DECLARE trick is needed with DBLib

$stmt->bindParam(1, $value, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);


$stmt->execute();

echo $value;

Go to the top of the page
+Quote Post
trueblue
post 19.08.2020, 15:23:29
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


https://stackoverflow.com/questions/1338292...meter-using-pdo


--------------------
Go to the top of the page
+Quote Post
pdusp
post 20.08.2020, 07:52:23
Post #3





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 19.08.2020

Ostrzeżenie: (0%)
-----


dziękuje, ale nadal nie znam poprawnego rozwiązania:

znalazłem wiele rzeczy, nie ma ostateczne rozwiązanie mojego problemu

np. piszą o bugu w mysql w 2010 roku...

$stmt = $db->prepare("CALL sp_returns_string(:in_string, @out_string)");
$value='pppppp';
$stmt->bindParam(':in_string', $value, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);

$stmt->execute();

// fetch the output
$outputArray = this->db->query("select @out_string")->fetch(PDO::FETCH_ASSOC);

print "procedure returned " . $outputArray['@out_string'] . "\n";

tu dostaje blad przez to this chyba....
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\xampp\htdocs\trace\test2.php on line 28
Go to the top of the page
+Quote Post
trueblue
post 20.08.2020, 08:08:46
Post #4





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


A skąd tam wzięło się "this"?


--------------------
Go to the top of the page
+Quote Post
pdusp
post 21.08.2020, 07:09:19
Post #5





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 19.08.2020

Ostrzeżenie: (0%)
-----


Trueblue, a pomożesz i doradzisz jak wyeliminować to this?
dziekuje
Piotr
Go to the top of the page
+Quote Post
trueblue
post 21.08.2020, 09:35:33
Post #6





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Może poprzez eliminację?

Jak wykonujesz wcześniejsze zapytania, np. CALL?


--------------------
Go to the top of the page
+Quote Post
pdusp
post 1.09.2020, 14:39:32
Post #7





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 19.08.2020

Ostrzeżenie: (0%)
-----


Podaje rozwiązanie, moze się komus jeszcze przyda?

$stmt = $db->prepare("CALL sp_returns_string(:in_1, :in_2, @out_string1, @out_string2)");
$value='pppppp';$value2='xxxx';
$stmt->bindParam(':in_1', $value, PDO::PARAM_STR , 4000);
$stmt->bindParam(':in_2', $value2, PDO::PARAM_STR , 4000);
$stmt->execute();

$outputArray = $db->query("select @out_string1, @out_string2")->fetch(PDO::FETCH_ASSOC);
// print_r($outputArray);

print "procedure returned: " . $outputArray['@out_string1'] . "\n";
print "procedure returned: " . $outputArray['@out_string2'] . "\n";
//print_r($result = $stmt->fetchAll(PDO::FETCH_CLASS));

pozdrawia
Piotr
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.04.2024 - 22:19