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

The Archive Base Latest Questions

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

I have just started a new PHP project and I was thinking it’s time

  • 0

I have just started a new PHP project and I was thinking it’s time to follow php suggestion and stop using mysql and swith to mysqli instead. But this gave me a problem.

Normaly my setup is like this

Index.php file and inside this file I have a 2 require statements. One that calls for the db.php file and one other to call a functions.php file. So far so good.

In the functions.php file a have a lot of different functions that is used all over the homepage and many of these are using SQL.
With php old mysql API this was no problem but it seams that the new mysqli api don’t allow connections to be used from included files???

For example in my db.php I have the connect statement. $db = mysql_connect(*******);
And in my function.php I have mysql_query(******) and it works perfect.

But if I change the db.php to $db = mysqli_connect(*****);
Then in my function.php file I can’t call the mysqli_query(***). (I have also tested object oriented but it gives me the same problem).

So how to get around this problem?
Is php expecting me to put the mysqli_connect statement in the beginning of every file that uses sql statements?

  • 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:47:18+00:00Added an answer on June 10, 2026 at 7:47 am

    Yes, MySQLi is object oriented and you need to pass around the $db object to the functions that need a database connection. The procedural alternatives also require the $db object to work. This is for your own good, as implicit global connections (actually: global state in any form) are bad practice. That the mysql extension allowed implicit connections was not good to begin with.

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

Sidebar

Related Questions

I have just started a new project, and I am using the Delphi 2009
we have just started using a git account of our Django website project so
So I'm really really really new to PHP and MySQL (just started today!). I
I have just started learning Jquery and am new to writing javascript (I am
I am new to NHibernate and have just started right now. I have very
I have just started using RSpec and I copied the very simple test on
I have just started implementing ISet 's instead of IList 's in my project
We just started a new project in Java EE in our office and i
I have just started connecting android app with php My file works very fine
I am pretty new to both php and mysql. I have a txt file

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.