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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:01:09+00:00 2026-06-08T02:01:09+00:00

I have tried connecting with php to my database but have been completely unsuccessful

  • 0

I have tried connecting with php to my database but have been completely unsuccessful ;( I keep getting something like: “PHP Notice: Undefined variable: conn” I have tried each of the following:

$conn = new PDO("mysql:host=localhost;dbname=ar_data", 'login', 'pass');
$conn = mysqli('localhost', 'login', 'pass', 'dbname') or die("error" :.mysqli_connect_error());
$conn = mysqli_connect('localhost', 'login', 'pass', 'ar_data') or die("error" :.mysqli_connect_error());

After I tried that last one I got this on a var_dump($conn) :

object(mysqli)#17 (18) { ["affected_rows"]=> int(0) ["client_info"]=> string(78) 
"mysqlnd 5.0.8-dev - 20102224 - $Id: SOME_VALUE_I_AM_CENSORING $" 
["client_version"]=> int(50008) ["connect_errno"]=> int(0) ["connect_error"]=> NULL 
["errno"]=> int(0) ["error"]=> string(0) "" ["field_count"]=> int(0) ["host_info"]=> 
string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=>
string(6) "5.5.25" ["server_version"]=> int(50525) ["stat"]=> string(140) "Uptime: 477847 
Threads: 6 Questions: 202259 Slow queries: 1 Opens: 1454 Flush tables: 1 Open tables: 10 
Queries per second avg: 0.423" ["sqlstate"]=> string(5) "00000" 
["protocol_version"]=> int(10)
["thread_id"]=> int(1506) ["warning_count"]=> int(0) }

Also I have tried using users that do not have privileges to the ar_data database and it will give me an error for that as expected. If I do var_dump($conn) right before a mysqli_prepare($conn, $sql) then it will print NULL. How can I connect to the DB?

Notes: I have changed the name from conn to other vars incase it was getting changed but still same behavior. I also have Drupal 7 and WordPress installed ( I imagine they are just using basic msql to connect)

UPDATE:

Entire file: https://dl.dropbox.com/u/6688861/phpconn.txt

  • 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-08T02:01:12+00:00Added an answer on June 8, 2026 at 2:01 am

    The last var_dump indicates that the connection is working fine. Your problem is that you’re referring to $conn in the ValidateForm() function without declaring global $conn in that function.

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

Sidebar

Related Questions

I have tried a lot but I have not been able to find out
I have tried searching over the internet about this problem but not able to
I have tried many permutations but they all don't seems to work well. Am
I have tried looking at the related links and googled this, but I haven't
I have a problem on linking files such as stylesheets, images, database connection file(db.php),
I have tried a session.php script which runs at the head of each page
I am not very experienced with database and php and I have a problem.
I have tried a very simple example of PHP MySQL Ajax following the example
I'm newish to PHP and OOP and I have been using the PDO class
i have a little problem while getting a value from database and post it

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.