Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6898969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:21:46+00:00 2026-05-27T07:21:46+00:00

i am used to writing regular pdo statements into php how can i continue

  • 0

i am used to writing regular pdo statements into php how can i continue doing that without having to learn active records or use whatever else method there is in CI

i did something like this

$sql = "select column1,column2 from table where column_id = :column_id and column_2 = :something"
$query = $db->query($sql);
$query->bindParam(":column_id", $_GET['value'], PDO::PARAM_INT);
$query->bindParam(":something", $_GET['something'], PDO::PARAM_STR);
$query->execute();

while($row = $query->fetch(PDO::FETCH_OBJ)
{
   print $row->data;
}

rather than using $_GET i can probably use $this->uri->segment()
which hopefully works with this…

I looked at active record and that looks like a huge bad idea, i dont know what Ellislab was thinking. no clue how complex queries can go into them. I am a newb learning from nettuts i can be wrong and please show me if i am. just speaking from what i have learned so far.

writing query statments the otherway such as

$query = $this->db->query(“my sql statement”) i would have to escape each value i am querying with codeigniters escape methods or just use mysql_real_escape_string. which is something i could of done to begin with before diving into the mvc world but i chose pdo because its something that already works well.

how can i implement what i am already used to?? I dont mind modifying core files , ill hopefully end up learning all the classes to reverse engineer it but until that day comes i’ll have hopefully written my own mvc.

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:21:47+00:00Added an answer on May 27, 2026 at 7:21 am

    Sorry, I fail to see how this:

    $query = $this->db->select('column1,column2')
                     ->from('table')
                     ->where('column_id',$this->input->get('value'))
                     ->where('column_2',$this->input->get('something'))
                     ->get();
    return $query->results();
    

    “looks like alot of extra work” rather than this:

    $sql = "select column1,column2 from table where column_id = :column_id and column_2 = :something"
    $query = $db->query($sql);
    $query->bindParam(":column_id", $_GET['value'], PDO::PARAM_INT);
    $query->bindParam(":something", $_GET['something'], PDO::PARAM_STR);
    $query->execute();
    

    Keep in mind that AR automatically escapes, so you don’t worry about SQL injections.

    If you’re more used to query bindings, you can also do

    $sql = "select column1,column2 from table where column_id = ? and column_2 = ?";
    $query = $this->db->query($sql, array($this->uri->segment(3), $something);
    

    and take advantage of parametrization, without using Active Record class.

    Nothing prevents you from using PDO, or even mysql_* for what that matters, instead of Active Record class. And your query has nothing that prevents CI from using it – apart from the $_GET array which you must enable, but can easily subsitute with $this->input->get() or fetch manually the URI segment or have it passed automatically to the controller’s method, as usually happens.

    You say “am a newb learning from nettuts” , but still say that Ellislabs doesn’t know what it’s doing; altough lightweight and far from perfect CI has a solid community, is actively developed and its general consensus is quite high; and if it decides to have the Active Record the way it is, there’s a reason.

    Also, consider that other more proper and real ORMs, like Propel or Doctrine, use a similar style in running queries (and you can use them too, instead of AR if you like it), taking advantage of PHP5 concatenation. An example taken right from the frontpage of propel:

    $books = BookQuery::create()  // retrieve all books...
      ->filterByPublishYear(2009) // ... published in 2009
      ->orderByTitle()            // ... ordered by title
      ->joinWith('Book.Author')   // ... with their author
      ->find();
    

    So I see nothing strange in the way CI’s Active Record is implemented or structured. If your code is not running, please give more details, like error codes and so on, so we can actually understand why it’s not working.

    IMPORTANT:

    I just read the changelog from the latest version; try downloading it (version 2.10), as they state:

    Added a PDO driver to the Database driver.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from a PHP background, I'm used to writing small functions that return a
I'm writing some web UI pages that can be used to create Linux user
I am writing a PHP script that accepts a regular expression pattern from the
I'm writing a webapp that will only be used by authenticated users. Some temporary
I am working writing a regular expression used to validate string in C. Here
I am used to writing data manipulation logic in SQL and now that I
What multi-threaded C++ library can be used for writing Linux, Windows, Solaris, and iPhone
On a regular basis I find myself writing little utility programs that use some
I'm currently writing a c++ console application that grabs the mouse position at regular
I am writing an application that records a users position at regular intervals whilst

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.