hazza326 Posted January 2, 2011 Share Posted January 2, 2011 Hello everyone, I'm new to php/mysql and am trying to setup a basic online address book script that has come straight from a tutorial book. I've created the tables etc and have the correct login details. I thought that was it but somehow I keep getting 'no database selected' in the top-left of the browser. Below is the file for opening the connection, is this a job for mysql_select_db and if so where would it need to go? i've been playing around but just cant get rid of that damn message, any help is massively appreciated : (login details hidden for security) <?php function doDB() { global $mysqli; //server and database connection $mysqli = mysqli_connect("serveraddress", "user", "pass"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } } ?> Thanks for having a look! Link to comment https://forums.phpfreaks.com/topic/223220-no-database-selected-tutorial-book-is-wrong/ Share on other sites More sharing options...
fortnox007 Posted January 2, 2011 Share Posted January 2, 2011 $mysqli = mysqli_connect("serveraddress", "user", "pass", "DATABASENAME"); Link to comment https://forums.phpfreaks.com/topic/223220-no-database-selected-tutorial-book-is-wrong/#findComment-1153984 Share on other sites More sharing options...
hazza326 Posted January 2, 2011 Author Share Posted January 2, 2011 Thanks for having a look, for some reason i'm still getting the same problem? seems like it really doesn't want to connect :-\ is there anything you could suggest trying? Link to comment https://forums.phpfreaks.com/topic/223220-no-database-selected-tutorial-book-is-wrong/#findComment-1153993 Share on other sites More sharing options...
fortnox007 Posted January 2, 2011 Share Posted January 2, 2011 yes i can error reporting: like this: $con = mysqli_connect('host','user','pass','database') or die(mysqli_error($con));//gives error when your connection is not right. $query ="SELECT * FROM your_table WHERE id = 4 LIMIT 1";//just some bogus query $result = mysqli_query($con, $query)or die(mysqli_error($con));//so it gives an error if you query sucks Link to comment https://forums.phpfreaks.com/topic/223220-no-database-selected-tutorial-book-is-wrong/#findComment-1154012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.