Can't Connect To Database Through PHP

Status
Not open for further replies.

majestyc

New Member
Messages
26
Reaction score
1
Points
1
I know I have the coding correct, I have even tried deleting and re-creating the user and connecting it to the database with all privileges. I've changed the password and even re-wrote the connection script. Nothing is allowing me to connect to the database through PHP. But with the control pannel I am able to get into phpMyAdmin and change everything as needed. My site was working one minute and then stopped the next...is there something going on with the server or database server?

<?php
$connect = mysqli_connect('localhost', 'trashntr_*****', '******', 'trashntr_*****');
?>
 

majestyc

New Member
Messages
26
Reaction score
1
Points
1
While checking this it tells me that it can not connect to localhost???
 

cryza9920

New Member
Messages
15
Reaction score
1
Points
3
I see that your user and database names are the same. Is that correct? This is how you should write the parameters for the 'mysqli_connect' function:
mysqli_connect("localhost", "db_user", "db_password", "db_name");
 

majestyc

New Member
Messages
26
Reaction score
1
Points
1
I see that your user and database names are the same. Is that correct? This is how you should write the parameters for the 'mysqli_connect' function:
mysqli_connect("localhost", "db_user", "db_password", "db_name");

I used the "" marks that you have suggested, the username and database name are different and I re-checked all those as well and they are all typed in correctly. I have added a bit to the end so I can check to see if the connection goes through.

mysqli_connect("localhost", "db_user", "db_password", "db_name") or die("Unable to Connect to localhost");

I still get the message that it is unable to connect even when everything is correct....I am going to export everything from PhpMyAdmin and then I will delete the database and re-create everything into a fresh database...maybe I have too many connections open (always forget to close connections)
 

majestyc

New Member
Messages
26
Reaction score
1
Points
1
upload_2019-9-17_8-27-16.png
This is what I am getting when trying to export my database...
 

majestyc

New Member
Messages
26
Reaction score
1
Points
1
SO! I found out that it is only my products table that is having issues...every other table can be exported and opened upload_2019-9-17_14-4-53.png
I can't drop the table, export, browse, or anything with that table....is it too large for the PHP to execute? What are some things that I can do to fix this issue if I can't do anything with it?
upload_2019-9-17_14-10-10.png

upload_2019-9-17_14-19-32.png
 

majestyc

New Member
Messages
26
Reaction score
1
Points
1
FINALLY FIGURED IT OUT! Apparently I had to create a new database, create a new database user, and transfer everything over to the new database. NOTICE!!! When doing php for mysql databases CLOSE THE CONNECTION! I apparently had exceeded the maximum amount of connections for the database user. UGH! Anyway...I updated my code and with every connection to the database I have I now end it with the propper mysqli_close(); tag. We will see if this helps later on.
 

cryza9920

New Member
Messages
15
Reaction score
1
Points
3
Everything should work correctly now. It isn't that important whether you use simple or double quotation marks '' / "", there is a small increase in performance when using simple quotation marks but insignificant. Anyway, it's a good habit to use 'mysqli_close()' to close the connection. Hope everything works well now.
 

majestyc

New Member
Messages
26
Reaction score
1
Points
1
Everything should work correctly now. It isn't that important whether you use simple or double quotation marks '' / "", there is a small increase in performance when using simple quotation marks but insignificant. Anyway, it's a good habit to use 'mysqli_close()' to close the connection. Hope everything works well now.

Yes it is working now. :)
 
Status
Not open for further replies.
Top