peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.31k stars 201 forks source link

Undefined method mysqli_stmt::get_result() #1051

Closed StefanduPlessis closed 2 years ago

StefanduPlessis commented 2 years ago

I'm having an issue with the Peachpie.Library.MySql.MySqli.mysqli_stmt.get_resultfunction. Below is a snippet of the code:

$connection = mysqli_connect($host, $username, $password);
$statement = $connection->prepare($query);
call_user_func_array(array($statement, 'bind_param'), $this->PassRefValues($parameters));
$statement->execute();
$result = $statement->get_result();

When trying to retrieve the result using $statement->get_result();, I get the following error:

An exception of type 'Pchp.Library.Spl.Error' occurred in Peachpie.Runtime.dll but was not handled in user code: 'Call to undefined method mysqli_stmt::get_result()'

However I did get around this by adding my own get_result function to the current context:

 context.DeclareFunction("get_result", new Func<mysqli_stmt, mysqli_result>((statement) => {
        return statement.get_result();
      }));

Do you perhaps have an idea what would be causing this reference issue or how to avoid it?

Here is the relevant decompiled php aswell, not sure if that will help you.

PhpValue result = call_get_result?6!.Target!(call_get_result?6, statement, <ctx>);
private static readonly CallSite<Func<CallSite?, PhpValue, Context?, PhpValue>?>? call_get_result?6 = CallSite<Func<CallSite, PhpValue, Context, PhpValue>>.Create(BinderFactory.InstanceFunction("get_result", typeof(Database).TypeHandle, typeof(PhpValue).TypeHandle));
jakubmisek commented 2 years ago

thanks for the issue.

Do you use the latest PeachPie release, and are the NuGet references in your project alright? There might be a reference to an old PeachhPie NuGet resulting in such an error. (you would see a warning message during build)

StefanduPlessis commented 2 years ago

Yes I do have the latest release. In the webapp i have the following references:

<PackageReference Include="Peachpie.AspNetCore.Mvc" Version="1.0.20" />
<PackageReference Include="Peachpie.Library" Version="1.0.20" />

In my Php library I have:

<Project Sdk="Peachpie.NET.Sdk/1.0.20">
<PackageReference Include="Peachpie.CodeAnalysis" Version="1.0.20" />
<PackageReference Include="Peachpie.App" Version="1.0.20" />

I also added the <PackageReference Include="Peachpie.Library.MySql" Version="1.0.20" /> package later on, but that did not resolve the issue.

jakubmisek commented 2 years ago

Thanks. I see there is an issue in mysql_stmt; working on it.

jakubmisek commented 2 years ago

@StefanduPlessis thanks again for the issue, it's fixed now.

It will be available in the next release of PeachPie.

StefanduPlessis commented 2 years ago

Thank you @jakubmisek!