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

  • Home
  • SEARCH
  • 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 8040033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:45:40+00:00 2026-06-05T03:45:40+00:00

I have an old mysql code which I want to convert into PHP data

  • 0

I have an old mysql code which I want to convert into PHP data object but I cant find on the web how this can be done, any help?

    $num = mysql_num_rows($result = mysql_query($query));

while($row = mysql_fetch_array($result))
  {

...
}

$query is a SELECT statement.

UPDATE:

My code is only showing the message “could not find driver” and notihng else, it isn’t showing form code or anything like that. What am i doing wrong in my PDO? I know database, hostname, username and password are correct so it should be able to show form and then let me connect to DB.

<?php

session_start(); 

$hostname = 'localhost';
$username="xxx";
$password="xxx";
$database="mobile_app";

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);


?>

,,, //Form Code is in here

<?php
if (isset($_POST['submit'])) {

$query = "
SELECT * FROM Teacher t  
WHERE 
(t.TeacherUsername = '".mysql_real_escape_string($teacherusername)."')
AND
(t.TeacherPassword = '".mysql_real_escape_string($teacherpassword)."')
";

$loged = false;

foreach ($dbh->query($sql) as $row)
  {

,,,, //results for each row



  }

 $dbh = null;

}

    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
 ?>
  • 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-05T03:45:42+00:00Added an answer on June 5, 2026 at 3:45 am
    try {
        $dbh = new PDO($dsn, $user, $password);
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }
    
    // PDOStatement is traversable, so you could use foreach.
    foreach ($dbh->query($sql) as $row) {
      //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an old mysql code which worked correctly in the application: $query =
I currently have a news website setup in PHP/MYSQL that's a bit old and
I have old code that uses size_t which IIRC comes from cstring.h. On OS
I have an old SQL Server 2000 database that I want to get into
I have an old J2EE application (J2EE 1.3), which packages into an EAR, and
I have this old-style non-PDO MySQL query (the code isn't tightened up, just to
I have a simple page in a PHP/MySQL web application that lets admin users
I have made a function in old mysql and now want to transfer it
I had an old mysql code where it successfully inserted values into the database.
Most of the software company have old software which continue maintain, and they also

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.