Comments (12)
This should work. How you build your query exactly, may you provide an example?
from pixie.
Before speaking about raw queries, what's the correct way to return an array on this case?
$query = QB::table('my_table')->where('name', '=', 'Sana');
$result = $query->get();
This will return objects. Is there a way I can make the get()
return arrays instead? Let's say that returning objects and then casting them to arrays is just inefficient. This can be done at the PDO level from the beginning.
I think ->get()
should accept a parameter defining the fetch type to be passed to PDO, like:
->get(\PDO::FETCH_ASSOC)
Or... we should be able to do something like:
$query = QB::table('my_table')
->where('name', '=', 'Sana')
->setFetchMode(\PDO::FETCH_ASSOC)
$result = $query->get();
What's your opinion?
With raw queries it could also be something similar like:
$query = QB::query('select * from cb_my_table where age = 12');
$query->setFetchMode(\PDO::FETCH_ASSOC);
var_dump($query->get());
Thank you.
from pixie.
setFetchMode(PDO::FETCH_ASSOC)
is the correct way to fetch entities as array.
from pixie.
I'm kinda confused, check this example:
<?php
require_once "vendor/autoload.php";
$config = [
"driver" => "mysql",
"host" => "127.0.0.1",
"port" => 3306,
"database" => "test",
"username" => "root",
"password" => "root",
"charset" => "utf8mb4",
"collation" => "utf8mb4_unicode_ci",
"prefix" => "",
"options" => [
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'"
],
];
// Start DB Connection
try {
$mysqlConnection = new \Pixie\Connection('mysql', $config);
} catch (\PDOException $e) {
print "Error establishing a database connection.";
exit();
}
// Instantiate a shared QueryBuilder
$db = new \Pixie\QueryBuilder\QueryBuilderHandler($mysqlConnection);
// Query Example
$query = $db->table("page")
->where("title", "=", "test title")
->setFetchMode(\PDO::FETCH_ASSOC);
$result = $query->get();
var_dump($result);
This returns:
Fatal error: Call to undefined method Pixie\QueryBuilder\QueryBuilderHandler::setFetchMode() in index.php on line 34
Isn't this implemented yet, the way you said, or I'm getting it wrong.
Thank you.
from pixie.
Do you have up-to-date version of Pixie?
from pixie.
I was getting it using "usmanhalalit/pixie": "1.*@dev"
on composer.json
... I changed it to dev-master
and not it works. Sorry and thank you for the feedback ;)
from pixie.
@TCB13 You are welcome. I guess issue now may be closed then.
from pixie.
Sure ;)
from pixie.
Note, I'll fork the documentation to add this. ;)
from pixie.
<select class="form-control">
<?php
echo "<option value='0'>-</option>";
$data = $base->select("level");
// $q=;
// foreach ($q as $key => $value) {
// }
try {
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='$row[id]'>$row[name]</option>";
}
} catch (PDOException $e) {
die($e->getMessage());
}
?>
</select>(
>
if like this what is the problem?
I'm sorry, because I'm a beginner
from pixie.
@kikideveloper Please check the docs and do it that way.
from pixie.
which documents @usman.it
from pixie.
Related Issues (20)
- try to add TIME function in WHERE HOT 4
- SELECT ... FOR UPDATE
- PDOException: 'SQLSTATE[55000]' on insert (lastInsertId) HOT 2
- Postgres: Update has syntax error HOT 1
- increment
- insert() doesn't work with table alias
- Update accumulating column
- Usage in a namespaced application and running CREATE statements HOT 2
- update and order by
- How to close connection? HOT 2
- pass array to where HOT 6
- Select with special characters HOT 2
- issue in count() HOT 3
- SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'data' at row 1 in
- How can i use external variable in transactions? HOT 2
- return random data HOT 1
- When updating data, does not write values containing double quotes to the database
- Error QueryBuilderHandler
- Group where HOT 2
- Nulls first construction in SQL query
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pixie.