- This topic is empty.
-
AuthorPosts
-
July 29, 2013 at 11:12 am #145058
Robin
ParticipantHello,
I have a file called config.inc.php, in this file I make the connection with my database:
<?php @$db = new mysqli('localhost','username','password','database'); if(mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } ?>
When I need the database connection I just include it in the page like this:
<?php include 'inc/head.inc.php'; include 'inc/config.inc.php'; $query = "SELECT * FROM <the table>"; $result = $db->query($query) or die($db->error); ?>
But when I look at the page it gives me the error.. Is there something wrong in my code?
Its probably some kind of stupid rookie mistake lol
Robin
July 29, 2013 at 11:54 am #145062makeshift67
Participanttry:
if($db->connect_errno)instead of :
if(mysqli_connect_errno())July 29, 2013 at 2:29 pm #145072Robin
Participant@makeshift67 I tried it and it doesn’t work
July 29, 2013 at 3:17 pm #145074makeshift67
Participantwhat does the error say? are the login credentials correct?
July 29, 2013 at 3:45 pm #145077Robin
ParticipantIt just says:
‘Error: Could not connect to database. Please try again later.’
For as far as I can tell the login credentials are like they’re suppose to be (even though my host wont let me choose my own database name, which sucks).
@$db = new mysqli('localhost','username','password','database');
localhost > just stays the same* username > crappy username host gave me password > password database > name of given database
* Is this suppose to stay the same? Or is it the url of the site where you have to login to access your database?
July 29, 2013 at 7:47 pm #145100waydechism5
ParticipantTry removing the @ in front of the $db variable.
July 30, 2013 at 3:19 am #145143Julia Anderson
Participantvery informative discussion. thanks for sharing such information.
http://www.mindmappingsite.com/sw-tool-reviews/software-reviews
July 30, 2013 at 3:46 am #145148Ashish Sinha
ParticipantHi,
I want to develop a PHP based shopping cart. Anybody can suggest me how can I start?
July 31, 2013 at 4:48 am #145254Robin
ParticipantThanks for the help @traq it was indeed that I put localhost where I should’ve put the url to the database server. So I did that still no luck. Then I mailed my host and they said that I have the wrong url (which is weird because that was the url they put in their FAQ).
But it finally works now!
Thanks again
Robin
July 31, 2013 at 4:58 am #145255Ashish Sinha
ParticipantThanks @Traq
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.