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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:04:28+00:00 2026-06-05T01:04:28+00:00

I have just discovered mysql and mysqli, so I’m really a beginner here. I

  • 0

I have just discovered mysql and mysqli, so I’m really a beginner here.
I have a function that I’m using (from an included php file) with all of the variables to connect to the server, OO style. It works like a charm for the home page, but I have a page (using a get request from a form) that tries to use the function and fails. Here is the function:

function connect(){
        $servername = "";
        $dbusername = "";
        $dbpassword = "";
        $dbname = "";
        $mysqli = new mysqli($servername, $dbusername, $dbpassword, $dbname);
        if($mysqli->connect_errno){
                echo "Failed to connect to MySQL: (".$mysqli->connect_errno.") ".$mysqli->connect_error;
        }
        return $mysqli;
}

Is there something about the GET request that’s stopping it? Is this inappropriate practice? I’ve been sorting through the docs, but I’m seriously confused. Here is the code I’m using to call the function:

include_once '/tools/config.php';#This is the file the function is in
                                 #(I even copied the text from the working file) 
$mysql = connect();

My debugging amounts to commenting out individual lines until it works. Might there be a better way? Thank you.

  • 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-05T01:04:29+00:00Added an answer on June 5, 2026 at 1:04 am

    There was nothing wrong with the syntax of this function. The problem was in my include statement. Thank you all for your help.

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

Sidebar

Related Questions

I have just discovered a nasty memory leak using both each_array() and each_arrayref() from
I have just discovered a variable name that is misspelled. If it were hidden
I have a website, and I just discovered that somehow someone injected JavaScript on
I have just installed composer in my /usr/bin folder, so when from that folder
I have just discovered that after upgrading to the latest Xcode 3.2.2, I am
I have just discovered that i need to start looking for a new job.
I just discovered that the Delphi TRibbonComboBox doesn't have an item index, and it
I just discovered that the following code executes without error (Chrome): console.log(fa); function fa(){}
I have just discovered that my app doesn't run in 4.3 even though the
I have just discovered that SQL Server CE doesn't allow you to batch queries.

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.