No Database Selected - PHP & MySQL

No Database Selected - PHP & MySQL

Unless you have the password incorrect and need to fix it, run a GRANT statement to grant access to your database user:

GRANT ALL PRIVILEGES ON aTable.* TO xxx@localhost IDENTIFIED BY 'password_for_xxx';

The above grants all privileges. It's often better to restrict to only what's needed. For example, if you only intend to SELECT, but not modify data,

GRANT SELECT ON aTable.* TO xxx@localhost IDENTIFIED BY 'password_for_xxx';

Update

Since you have identified the database name as dedbmysql, change your mysql_select_db() call to:

$db = mysql_select_db("dedbmysql", $con);

Following this, the GRANT statements above are probably unnecessary, as your host may have already worked out the correct database permissions.

No database selected error even after a db is selected

You forgot to pass the variable $link as the link parameter.

     mysql_select_db('database', $link) or die(mysql_error());

EDIT: Try passing the database in the FROM parameter like

     SELECT * FROM `database`.`table`

No database selected, even though explictly stated

Specify the database name as the fourth parameter to mysqli_connect()

Here's an example that assumes you're connecting on localhost:

$conn2 = mysqli_connect("localhost", "your_username", "your_password", "ambition");

or do mysqli_select_db("ambition") before your mysqli_prepare statement if ambition was not your default database.

No database selected when importing in phpMyAdmin

the problem is right there in the error message: you haven't said which database you want to put this data in.

either create a new one, or click on the one you want to use from the left menu.

How to fix: Error- No database selected

you did not defined the database name in the connection

<?php
$servername = "sql308.epizy.com";
$username = "epiz_19848473";
$password = "huihuibuh";
$dbname = "DATABASE_NAME_HERE";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

else you can define define the database name in the connection

$conn = new mysqli($servername, $username, $password, "DATABASE_NAME_HERE");

insert into php database No Database Selected Error

Looks like your connection syntax is incorrect

Try this:

$conn = mysqli_connect($servername, $username, $password, $db_name) or die( mysqli_connect_error());
// By default $username = 'root' and $password = ''

$sql = "INSERT INTO dss (emp_name, average, date) VALUES ('".$name."', '".$average."', '".$date."')";

Hope this helps.

Peace! xD

Mysql No Database selected error when using PHP

Finally I got it working ! I still fail to understand why the PHP Query fails. Anyways, the query itself was simple which I copied from SO question Delete all rows which has no id existing in another table.

What i could make out is that using alias was problematic and finally I used full table name with DB and it worked perfectly. I am pretty sure that alias can be used, its just that I am not expert in them !

mysqli_query($connection,"DELETE db.table1 FROM db.table1 LEFT JOIN db.table2 ON table1.id = table2.id WHERE table2.id IS NULL");

Error: 'No database selected'

You cannot connect using a PDO connection and then use a mysqli_ function call.

If you have used mainly mysqli_ functions then change your connection to use a mysqli connection like this.

define('DBHOST','localhost');
define('DBUSER','root');
define('DBPASS','root');
define('DBNAME','members');
$db = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME, 8889);
//$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


Related Topics



Leave a reply



Submit