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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.