Git Product home page Git Product logo

Comments (12)

neoascetic avatar neoascetic commented on August 19, 2024

This should work. How you build your query exactly, may you provide an example?

from pixie.

TCB13 avatar TCB13 commented on August 19, 2024

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.

neoascetic avatar neoascetic commented on August 19, 2024

setFetchMode(PDO::FETCH_ASSOC) is the correct way to fetch entities as array.

from pixie.

TCB13 avatar TCB13 commented on August 19, 2024

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.

neoascetic avatar neoascetic commented on August 19, 2024

Do you have up-to-date version of Pixie?

from pixie.

TCB13 avatar TCB13 commented on August 19, 2024

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.

neoascetic avatar neoascetic commented on August 19, 2024

@TCB13 You are welcome. I guess issue now may be closed then.

from pixie.

TCB13 avatar TCB13 commented on August 19, 2024

Sure ;)

from pixie.

TCB13 avatar TCB13 commented on August 19, 2024

Note, I'll fork the documentation to add this. ;)

from pixie.

kikideveloper avatar kikideveloper commented on August 19, 2024
<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>(

> 

screenshot_2
if like this what is the problem?
I'm sorry, because I'm a beginner

from pixie.

usmanhalalit avatar usmanhalalit commented on August 19, 2024

@kikideveloper Please check the docs and do it that way.

from pixie.

kikideveloper avatar kikideveloper commented on August 19, 2024

which documents @usman.it

from pixie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.