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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:01:20+00:00 2026-06-05T02:01:20+00:00

Following is my piece of code in which I am trying to create database

  • 0

Following is my piece of code in which I am trying to create database connectivity. Please see the comments below in the code in which I mentioned where exactly the problem is occurring. Moreover, I also mentioned one connectivity code that is working fine.

Please let me know how I can call my dbconfig.php so it’ll behave like that piece of code that results to successful connection.

Thanks

<?php

//Including Header file for the connectivity to the database
require_once('Connections/dbconfig.php');

  mysql_select_db($database_dbconfig, $dbconfig);
  // If I use the following line of code for connectivity then it works perfectly fine:
  //$dbh = new PDO('mysql:host=localhost;dbname=rare','root','');
  $dbh= $dbconfig;
  $q = 'select resident_id,u_first,u_last from z_events group by resident_id';
  /*
  The following error will occur when I try to make a connection from the header file:
  Fatal error: Call to a member function prepare() on a non-object in C:\Users\QAD\Downloads\CAR\index12 - Copy.php on line 200 
  */
  $user = $dbh->prepare($q);
  $user->execute();
?>

dbconfig.php

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_dbconfig = "localhost";
$database_dbconfig = "rare";
$username_dbconfig = "root";
$password_dbconfig = "";
$dbconfig = mysql_pconnect($hostname_dbconfig, $username_dbconfig, $password_dbconfig) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
  • 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-05T02:01:22+00:00Added an answer on June 5, 2026 at 2:01 am

    You are mixing mysql_* functions with PDO functions – first connecting to your database using mysql_connect and then using prepare() to query your database.

    You should move to PDO completely, replace this line:

    $dbconfig = mysql_pconnect($hostname_dbconfig, $username_dbconfig, $password_dbconfig) or trigger_error(mysql_error(),E_USER_ERROR); 
    

    With this one:

    $dbconfig = new PDO('mysql:dbname=' . $database_dbconfig . ';host=127.0.0.1', $username_dbconfig, $password_dbconfig);
    

    And put this in your other file:

    <?php
    
    //Including Header file for the conectivity to the database
    require_once('Connections/dbconfig.php');
    
      $dbh = $dbconfig;
      $q = 'select resident_id,u_first,u_last from z_events group by resident_id';
      $user = $dbh->prepare($q);
      $user->execute();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following piece of code which posts some data into database: $post =
I have following piece of code in my jsp file which getSession information: <jsp:useBean
I have been trying to find ways to make the following piece of code
I have the following piece of code and am trying to do something simple
Debugging the following piece of code I get Source not found notification which probably
I have the following piece of code, which is part of a WPF 4
I'm trying to edit a piece of code written by a development company, which
I have the following piece of code which outputs a long article: <?php the_content();
One of the following pieces of code generates a memory leak, any idea which
The following piece of code is used to print the time in the logs:

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.