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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:40:59+00:00 2026-06-18T07:40:59+00:00

Been always used MySQL with PHP with the typical mysql_query or mysql_fetch_array but now

  • 0

Been always used MySQL with PHP with the typical mysql_query or mysql_fetch_array but now i’m moving to PDO: Prepared Statement since it will be the future.

I’m newbie and using it for personal so i decide to ask you how to rewrite all this in rules of PDO: Prepared Statement

Let us suppose we’ve the following database users(id,name,job,number)

CREATE TABLE `users` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `name` varchar(255) default '0',
  `job` varchar(255) default NULL,
  `number` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

INSERT INTO `users` VALUES (1, 'John', 'Plumber', '555');
INSERT INTO `users` VALUES (2, 'Iva', 'Reporter', '666');
INSERT INTO `users` VALUES (3, 'Robert', 'Writer', '777');
INSERT INTO `users` VALUES (4, 'Irin', 'Writer', '888');

Now those are of normal Mysql so can anyone rewrite to be with PDO: Prepared Statement

1) Connection

$DB["host"]   = "localhost";
$DB["dbName"] = "dbname";
$DB["user"]   = "dbuser";
$DB["pass"]   = "dbpass";
$link = mysql_connect($DB["host"],$DB["user"],$DB["pass"]) or die("Connection Failed");
mysql_select_db($DB["dbName"]);

2) Call from the database exact entry

$sql = "select * from users where job='Plumber'";
$reg = mysql_query($sql) or die(mysql_error());
$aee = mysql_fetch_array($reg);

echo $aee[name]; // should gives name John

3) Call from the database results

$qry="select * from users where job='Writer'";
$result=mysql_query($qry) or die($qry);

if(mysql_num_rows($result)=='0'){

echo "No results"; // if not found any for this conditional job

}else{
while($line=mysql_fetch_array($result)){

echo $line[name]."<br>"; // should gives Robert <br> Irin

}
}

That would really helps me a lot and discourage me to open next new question for insert,update,delete as i believe this helpful for newbies like me ~ 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-06-18T07:41:00+00:00Added an answer on June 18, 2026 at 7:41 am

    The PDO manual is an excellent resource for learning PDO for almost any situation. Prepared statements may seem bizarre and hard at first, but you will come to love them once you master some basics…

    PDO SELECT…

    $db = new PDO("mysql:host=localhost;dbname=db", "user", "password");
    
    $query = "SELECT * FROM users WHERE name = " . $db->quote($name);
    
    $result = $db->query($query);
    
    while($row = $result->fetch(PDO::FETCH_ASSOC)) {
        print_r($row);
    }
    
    $result->closeCursor();
    

    PDO INSERT…

    $query = $db->prepare("INSERT INTO users (first_name, last_name, email) VALUES (:fname, :lname, :email)");
    
    // bind params
    $query->bindParam(":fname", $firstName);
    $query->bindParam(":lname", $lastName);
    $query->bindParam(":email", $email);
    
    // execute the query
    $query->execute();
    

    In spite of the last (simple) example, I would also encourage you to learn how to do INSERT queries for multiple values in one query. It’s not only faster than doing many single INSERTs, it’s also considered good practice.

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

Sidebar

Related Questions

I have been using Unity for quite a while but I have always used
Hello I have been working for a while with PHP and MySQL. Now I
I've been working with JQuery for some time now and I've always used the
I have always been kind of confused by threads, and my class right now
I've always been used to using String instead of string and Int32 instead of
I have been programming in Python for a few years now and have always
I've been building Wordpress widgets for a while and have always used some code
I've been always trying to avoid using Sessions. I've used spring security or other
Possible Duplicate: PhpMailer vs. Swiftmailer? I have always used PHP's built in mail() function
While I've been writing php for a long time, it was always a skill

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.