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 8437939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:34:17+00:00 2026-06-10T07:34:17+00:00

Consider 2 ways of querying the database: With a framework (Yii): $user = Yii::app()->db->createCommand()

  • 0

Consider 2 ways of querying the database:

With a framework (Yii):

$user = Yii::app()->db->createCommand()
->select('id, username, profile')
->from('tbl_user u')
->join('tbl_profile p', 'u.id=p.user_id')
->where('id=:id', array(':id'=>$id))
->queryRow();

With string concatenation (separating individual parts of a SQL statement):

$columns = "id,username,profile"; // or =implode(",",$column_array);
//you can always use string functions to wrap quotes around each columns/tables
$join = "INNER JOIN tbl_profile p ON u.id=p.user_id";
$restraint = "WHERE id=$id ";//$id cleaned with intval()
$query="SELECT $columns FROM tbl_user u {$restraint}{$join}";
//use PDO to execute query... and loop through records...

Example with string concatenation for pagination:

$records_per_page=20;
$offset = 0;
if (isset($_GET['p'])) $offset = intval($_GET['p'])*$records_per_page;
Squery="SELECT * FROM table LIMIT $offset,$records_per_page";

Which method has better performance?

  • PHP’s PDO allows code to be portable to different databases
  • 2nd method can be wrapped in a function so no code is ever repeated.
  • String concatenation allows building complex SQL statements programmatically (by manipulating strings)
  • 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-06-10T07:34:18+00:00Added an answer on June 10, 2026 at 7:34 am

    Use which is right for you and your project team. Frameworks are written for a reason, so use them if it suits, but if it doesn’t (and there are reasons they don’t) then fall away.

    I don’t know Yii, but if you look at a lot of frameworks, all they do is build a string query from the parts at the end of the day, hopefully taking advantage of parametization but not always. So, regarding speed, string concat is probably “fastest” – but you’re unlikely to really see the difference with a stop watch (you could benchmark if you needed with 1000 queries, but other features such as better error checking or caching may unfairly slow or speed up hte results).

    But one advantage frameworks have is they can add context-sensitive caching and know when you update table X that you query caches for A, D and F need to be deleted, but queries B, C and E are all good.

    You also have “easy to read” and “debug” and “functionality” to worry about. The top example is much easier to read, which is important in a shared project.

    You also need to consider prepared statements – does the framework use them? If so, does it allow you to re-use them (as opposed to merely using them for syntax purposes).

    But can the framework do sub-selects? Can it do parametization inside the “JOIN ON”? If not, string concatination with PDO may be more appropriate.

    It’s not a hard and fast answer – but hopefully provides all the points you need to consider.

    Recommendation: use framework unless you really notice it being slow, using too much memory or there is some other good reason not to.

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

Sidebar

Related Questions

Consider that there are 100 plus ways of interrupts occuring from various sensors. There
Consider following piece of code: declare @var bit = 0 select * from tableA
Consider a simple query: SELECT id, date, hours FROM employees where id=10 And the
Consider the following ways of declaring and initializing a variable of type C :
Consider the string 55,33,255,66,55 I am finding ways to count number of occurence of
What would you consider the proper way of storing a simple username string in
For the sake of brevity consider a facebook style image content serving app. Users
I just realized I can add an event handler in two ways: Consider an
Consider this example, it shows two possible ways of lazy initialization. Except for being
Consider the following two ways of writing a loop in Java to see if

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.