Jump to content

'No database selected' - Tutorial book is wrong?


hazza326

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.