Closed AdhamKasim closed 7 years ago
Can you please share a code example? Im not entirely sure what your issue is.
The question marks are expected, values are automatically converted to prepared statements. The builder callback should always receive a query string (with the question marks) and array of values.
Hi Mario,
please note i did the following steps:
$res = $hydrahon->table('people')->insert(
[
['name' => 'Ray', 'age' =>25],
['name' => 'Jhon', 'age' =>30],
['name' => 'Adham', 'age' =>22],
])->execute();
people
(age
,
name
) values (?, ?), (?, ?), (?, ?). i think the question mark is not
normal in this level!please let me in touch if this issue solved.
On Wed, Aug 16, 2017 at 11:39 AM, Mario Döring notifications@github.com wrote:
Can you please share a code example? Im not entirely sure what your issue is.
The question marks are expected, values are automatically converted to prepared statements. The builder callback should always receive a query string (with the question marks) and array of values.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ClanCats/Hydrahon/issues/8#issuecomment-322691440, or mute the thread https://github.com/notifications/unsubscribe-auth/ANqo18epz6njUbT7k2FVOrlVIzAXrTqmks5sYpy4gaJpZM4O4PbU .
we can skype if the problem still not clear for you 🙂
Best,
On Wed, Aug 16, 2017 at 3:11 PM, Adham Kassem muhammed.alkassem@gmail.com wrote:
Hi Mario,
please note i did the following steps:
- install the query builder lib by composer.
- make a "people" table with Id, age and name columns "Id is auto-increment".
- i tried to execute the following statement supplied by docs:
$res = $hydrahon->table('people')->insert(
[
['name' => 'Ray', 'age' =>25], ['name' => 'Jhon', 'age' =>30], ['name' => 'Adham', 'age' =>22],
])->execute();
- i checked the table data, no data were found.
- i printed the $queryString which is a parameter of the builder callback function and it was like this: insert into
people
(age
,name
) values (?, ?), (?, ?), (?, ?). i think the question mark is not normal in this level!- for further details i attached the test project which include the queryBuilder lib and a simple index.php file to test , please check it then execute it to know what i mean.
please let me in touch if this issue solved.
On Wed, Aug 16, 2017 at 11:39 AM, Mario Döring notifications@github.com wrote:
Can you please share a code example? Im not entirely sure what your issue is.
The question marks are expected, values are automatically converted to prepared statements. The builder callback should always receive a query string (with the question marks) and array of values.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ClanCats/Hydrahon/issues/8#issuecomment-322691440, or mute the thread https://github.com/notifications/unsubscribe-auth/ANqo18epz6njUbT7k2FVOrlVIzAXrTqmks5sYpy4gaJpZM4O4PbU .
It's not a bug it's a feature! Jokes aside, the generated query is 100% correct.
Here the full working example taken from the docs:
<?php
require "vendor/autoload.php";
$connection = new PDO('mysql:host=localhost;dbname=hydrahon', 'root', '');
// create a new mysql query builder
$hydrahon = new \ClanCats\Hydrahon\Builder('mysql', function($query, $queryString, $queryParameters) use($connection)
{
$statement = $connection->prepare($queryString);
$statement->execute($queryParameters);
// when the query is fetchable return all results and let hydrahon do the rest
if ($query instanceof \ClanCats\Hydrahon\Query\Sql\FetchableInterface)
{
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}
});
// insert people
$hydrahon->table('people')->insert(
[
['name' => 'Ray', 'age' => 25],
['name' => 'John', 'age' => 30],
['name' => 'Adham', 'age' => 22],
])->execute();
// get and print people
$result = $hydrahon->table('people')->select()->get();
print_r($result);
Output:
Array
(
[0] => Array
(
[id] => 1
[name] => Ray
[age] => 25
)
[1] => Array
(
[id] => 2
[name] => John
[age] => 30
)
[2] => Array
(
[id] => 3
[name] => Adham
[age] => 22
)
)
Thanks Mario,
I know, but the insert statement is not functional. 🙂
try to print the statement before you execute it in the function callback
body, for me i got this:
insert into people
(age
, name
) values (?, ?), (?, ?), (?, ?)
which is not insert-able
i hope thats help
On Wed, Aug 16, 2017 at 3:29 PM, Mario Döring notifications@github.com wrote:
It's not a bug it's a feature! Jokes aside, the generated query is 100% correct.
Here the full working example taken from the docs:
<?phprequire "vendor/autoload.php";$connection = new PDO('mysql:host=localhost;dbname=hydrahon', 'root', '');// create a new mysql query builder$hydrahon = new \ClanCats\Hydrahon\Builder('mysql', function($query, $queryString, $queryParameters) use($connection){ $statement = $connection->prepare($queryString); $statement->execute($queryParameters); // when the query is fetchable return all results and let hydrahon do the rest if ($query instanceof \ClanCats\Hydrahon\Query\Sql\FetchableInterface) { return $statement->fetchAll(\PDO::FETCH_ASSOC); }});// insert people$hydrahon->table('people')->insert([ ['name' => 'Ray', 'age' => 25], ['name' => 'John', 'age' => 30], ['name' => 'Adham', 'age' => 22],])->execute();// get and print people$result = $hydrahon->table('people')->select()->get();print_r($result);
Output:
Array ( [0] => Array ( [id] => 1 [name] => Ray [age] => 25 )
[1] => Array ( [id] => 2 [name] => John [age] => 30 ) [2] => Array ( [id] => 3 [name] => Adham [age] => 22 )
)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ClanCats/Hydrahon/issues/8#issuecomment-322741710, or mute the thread https://github.com/notifications/unsubscribe-auth/ANqo14-otSPJXf6L32cUTE6Qb9CxlhBQks5sYtJ7gaJpZM4O4PbU .
the insert query builder string returned "insert into
people
(age
,name
) values (?, ?), (?, ?), (?, ?)" with question mark! in Mysql.php param($value) is returning a question mark! i replace it with "$value" then the query syntax was correct.to fix this either to return $value insted question mark in param($a) function body or to return the $value from addParameter($a) function.