Luigi123 Posted February 23, 2018 Posted February 23, 2018 Hello,Why am I receiving this error when I try to install a donation website for my community?: Fatal error: Call to a member function listGroups() on null in /home/luigi123/public_html/donations/index.php on line 113 Also, when I try to login, I receive this error as well. Unable to open connection to MySQL server.
Krydos Posted February 23, 2018 Posted February 23, 2018 Do you have your db host, user, database, etc. filled out correctly?
sagnik Posted February 23, 2018 Posted February 23, 2018 The first error is occurring because it may be depended on the MySQL connection variable. If you could open the connection to mysql successfully, it should disappear. Otherwise, if it's not depended on mysql variable then, probably you are calling a function of a class without initializing the class.
Luigi123 Posted February 23, 2018 Author Posted February 23, 2018 Do I have to request to open connection for mysql?
sagnik Posted February 23, 2018 Posted February 23, 2018 You can open a connection to MySQL by doing:$db=mysqli_connect($host,$user,$pwd,$db);Then use the variable to your script. I need to see the code to say anything.
Luigi123 Posted February 23, 2018 Author Posted February 23, 2018 How do I do it in order to open a connection for mysql?
sagnik Posted February 23, 2018 Posted February 23, 2018 If you do the above a connection to MySQL database will be opened. You don't need to do anything else.
Luigi123 Posted February 23, 2018 Author Posted February 23, 2018 In which file do I add the code? Sorry I’m asking too many questions. I’m just trying my best to get this fix.
sagnik Posted February 23, 2018 Posted February 23, 2018 No problem, you can as many as you have, I would love to help you. Well, can you post your code here?
Luigi123 Posted February 24, 2018 Author Posted February 24, 2018 Which php file do you want to me to post here?
Luigi123 Posted February 24, 2018 Author Posted February 24, 2018 Plus, I don't know how to open a connection to mysql with this code: $db=mysqli_connect($host,$user,$pwd,$db); Can you tell me the steps what to do so I can get this fix?
sagnik Posted February 24, 2018 Posted February 24, 2018 Take this example:<?php $host="localhost"; $user="user_example"; $pwd="password"; $db="user_database"; $con=mysqli_connect($host,$user,$pwd,$db) or die("Couldn't connect to the database: ".mysqli_error($con)); if($q=mysqli_query($con,"SELECT field1, field2 FROM example_table")){ if(db_num_rows($q) > 0){ while($r=mysqli_fetch_array($q)){ echo "Field1 Value: {$r['field1']}"; echo "<br>"; echo "Field2 Value: {$r['field1']}"; } } else { echo "No rows found: The table seems to be empty."; } } else { echo "Unable to query database: ".mysqli_error($con); } ?>
Luigi123 Posted February 24, 2018 Author Posted February 24, 2018 Alright, I have filled out the database details. What do I do next?
sagnik Posted February 24, 2018 Posted February 24, 2018 Post the code of the class as well as the script that's calling the class function. Otherwise I don't able to help you.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now