Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This MySqlConnection is already in use #1069

Closed
BKSoftCraft opened this issue Sep 21, 2022 · 8 comments
Closed

This MySqlConnection is already in use #1069

BKSoftCraft opened this issue Sep 21, 2022 · 8 comments

Comments

@BKSoftCraft
Copy link

//--------------------------------------------------------index.php-------------------------------------------------------------
<?php
require "dbconn.php";
$flag = 1;
$conn->beginTransaction();
$sdate = "2022-09-15";
$stdate = "2022-09-21";
$total_amt = 100;
// Insert
$i_sql = "INSERT INTO 00test (date,value) VALUES (:date,:value)";
$i_stmt = $conn->prepare($i_sql);
// Update
$u_sql = "UPDATE 00test SET value = value + :amt WHERE date >= :date";
$u_stmt = $conn->prepare($u_sql);

while ($sdate < $stdate) {
    $i_rs = $i_stmt->execute([':date' => $sdate, ':value' => $total_amt]);
    if (!$i_rs) {
        $showError = "Unable to Insert data";
        $flag = 0;
    }
    $sdate = date('Y-m-d', strtotime($sdate . ' +1 day'));
}
$u_rs = $u_stmt->execute([':amt' => $total_amt, ':date' => $stdate]);      // Peachpie.Library.PDO.PDOException: 'This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse'
if (!$u_rs) {
    $showError = "Unable to Update data";
    $flag = 0;
}
if ($flag == 0) {
    $conn->rollBack();
} else {
    if (!$conn->commit()) {
        echo "Commit Fail";
    } else {
        echo "Success";
    }
}
//---------------------------------------------------------------dbconn.php-------------------------------------------------------------
<?php
try {
    $server = "localhost";
    $username = "root";
    $password = "";

    $conn = new PDO("mysql:host=$server;dbname=test1", $username, $password);
    $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (Exception $e) {
    echo "Failed: " . $e->getMessage();
}
@BKSoftCraft
Copy link
Author

Peachpie.Library.PDO.PDOException
  HResult=0x80131500
  Message=This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse
  Source=Peachpie.Library.PDO
  StackTrace:
   at Peachpie.Library.PDO.PDO.HandleError(ErrorInfo error)
   at Peachpie.Library.PDO.PDOStatement.HandleError(ErrorInfo error)
   at Peachpie.Library.PDO.PDOStatement.HandleError(Exception exception)
   at Peachpie.Library.PDO.PDOStatement.execute(PhpArray input_parameters)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at <Root>.index_php.<Main>(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>) in D:\vs\TestWeb\TestWeb\TestWeb\TestWeb\index.php:line 23
   at <Root>.index_php.<Main>`0(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>)
   at Pchp.Core.Context.ScriptInfo.Evaluate(Context ctx, PhpArray locals, Object this, RuntimeTypeHandle self)
   at Peachpie.AspNetCore.Web.RequestContextCore.ProcessScript(ScriptInfo script, String path_info)

@BKSoftCraft
Copy link
Author

BKSoftCraft commented Sep 21, 2022

this work well in core php but in peachpie it throw error.
Error : Peachpie.Library.PDO.PDOException: 'This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse
Is any solution for this ?

@jakubmisek
Copy link
Member

this work well in core php but in peachpie it throw error. Error : Peachpie.Library.PDO.PDOException: 'This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse Is any solution for this ?

please note, PeachPie is not PHP. It is a new implementation, it does not use anything from "Core" PHP

@jakubmisek
Copy link
Member

Peachpie.Library.PDO.PDOException
  HResult=0x80131500
  Message=This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse
  Source=Peachpie.Library.PDO
  StackTrace:
   at Peachpie.Library.PDO.PDO.HandleError(ErrorInfo error)
   at Peachpie.Library.PDO.PDOStatement.HandleError(ErrorInfo error)
   at Peachpie.Library.PDO.PDOStatement.HandleError(Exception exception)
   at Peachpie.Library.PDO.PDOStatement.execute(PhpArray input_parameters)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at <Root>.index_php.<Main>(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>) in D:\vs\TestWeb\TestWeb\TestWeb\TestWeb\index.php:line 23
   at <Root>.index_php.<Main>`0(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>)
   at Pchp.Core.Context.ScriptInfo.Evaluate(Context ctx, PhpArray locals, Object this, RuntimeTypeHandle self)
   at Peachpie.AspNetCore.Web.RequestContextCore.ProcessScript(ScriptInfo script, String path_info)

thank you for the stack trace; seems like a bug. To test it, we would need the test database as well.

@BKSoftCraft
Copy link
Author

//This is database data which i used for testing
CREATE TABLE `00test` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL,
  `value` decimal(20,3) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4

// I have same issue before with id #990 but that test work fine.

@BKSoftCraft
Copy link
Author

This database file
test1.zip

@jakubmisek
Copy link
Member

awesome, thanks!

@jakubmisek
Copy link
Member

Thanks for the detailed test case. Using two or more pdo statements has been fixed.

Preparing release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants