catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Problem about using custom query #839

Closed ghost closed 5 years ago

ghost commented 5 years ago

我在使用medoo的过程中遇到一个问题,但是我无法自己解决,使用 $database->pdo->setAttribute(***) 我无法创建mysql的event定时任务,想知道是否是我自己用错了,请您看到后务必回复我一下,下面直接上截图。 github-medoo-1 github-medoo-2

再次感谢。

catfan commented 5 years ago

I don't know why you use query() like this. Using query() to execute custom query without quotation from pdo object is not the way we recommended.

Please read our documentation about how to create custom query and consider using quotation syntax instead.

https://medoo.in/api/query

ghost commented 5 years ago

Thank you very much for your answer. I am probably a bit confused. Maybe the method used is wrong. I will try other methods again later, thank you again for your answer.

ghost commented 5 years ago

@catfan Sorry, I am bothered, I still want to ask a question.

When I use PDO->query, I can create event scheduling tasks. When I use medoo->query, I can't create event scheduling tasks.

Please see the screenshot below.

  1. Use PDO pdo1 2.Use Medoo pdo2 log

Results of two executions result

Looking forward to your reply!

catfan commented 5 years ago

Did you really read the documentation and the link I replied above? Especially the quotation warning for custom query.

There is nothing I can help if you still using like this way.

ghost commented 5 years ago

@catfan I am very sorry, I have learned the lesson. But I can't create it using the following method, but also use debug() to print it out. Maybe I still don't know how to write it. Please give me some help. thank you very much. Medoo SQL

$order_number = 'O'.date('YmdHis').rand(100000, 999999);

$database->debug()->query('CREATE DEFINER = <root>@<localhost> EVENT <' . $order_number . '> ON SCHEDULE AT : dateTime ON COMPLETION NOT PRESERVE ENABLE DO call closeTrade(: order);', [
    ': dateTime' => date('Y-m-d H:i:s', strtotime("+1 day")),
    ': order' => $order_number
]);

Print result


CREATE DEFINER = `root`@`localhost` EVENT `O20190523101243432968` ON SCHEDULE AT '2019-05-24 10:12:43' ON COMPLETION NOT PRESERVE ENABLE DO call closeTrade('O20190523101243432968');

Looking forward to your reply.😊😊

ghost commented 5 years ago

@catfan After trying N times, I finally succeeded. I used the following method.


$order_number = 'O'.date('YmdHis').rand(100000, 999999);

$my_db->query("CREATE DEFINER = <root>@<localhost> EVENT <$order_number> ON SCHEDULE AT :dateTime ON COMPLETION NOT PRESERVE ENABLE DO call closeTrade(:order);", [
    ':dateTime' => date('Y-m-d H:i:s', strtotime("+1 day")),
    ':order' => $order_number
]);

:variable No spaces can be used in the middle.

I am very sorry, this is the problem caused by my mistake and I am very grateful for your answer.😊😊

catfan commented 5 years ago

@programmexwz Congratulations on your success. Additionally, there is no need for the last ;.