What should I do to solve this error?
Error:
Fatal error: Uncaught mysqli_sql_exception: Unknown database 'testdb' in D:\xampp\htdocs\dashboard\project\connection.php:6 Stack trace: #0 D:\xampp\htdocs\dashboard\project\connection.php(6): mysqli->__construct('localhost', 'root', '#Geoinformatici...', 'testdb') #1 {main} thrown in D:\xampp\htdocs\dashboard\project\connection.php on line 6
Code in Bracket IDE
<?PHP
$server = 'localhost';
$username = 'root';
$password = '#Geoinformaticionno1';
$database = 'testdb';
$connection = new mysqli($server, $username, $password, $database) or die("not connected");
echo "connected"
?>
Let me know if any other thing is required to see to solve this error.
You just have to specify the server port in these brackets.
<?PHP
$server = 'localhost';
$username = 'root';
$password = '#Geoinformaticionno1';
$database = 'testdb';
$connection = new mysqli($server, $username, $password, $database, 3307) or die("not
connected");
echo "connected"
?>
our local system or localhost has defualt user is root & password is `` that means blank.
if, you using add password from your end, for accessing phpmyadmin, then you can add your setted password. But, default, value user is: root & password is blank.
Related
I`m working on a java swing app. so that i have created a database called c_app in MySQL server workbench. what i need is to fetch data into a HTML page using PHP.
$username = "root";
$password = "";
$hostname = "localhost:3307";
$db = "c_app";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password, $db)
or die("Unable to connect to MySQL");
This code segment gives me Warning: mysqli_connect(): (HY000/1049): Unknown database 'c_app' in C:\xampp\htdocs\C_AppWeb\linkpage.php on line 7
Unable to connect to MySQL
What is the problem here? do i need phpmyadmin database rather than MySQl database? can anyone help me?
First one, both phpmyadmin and workbench are not database. They are tools to work with database.
I see you use port 3307 in your code, so let you try:
$username = "root";
$password = "";
$hostname = "localhost";
$port = 3307;
$db = "c_app";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password, $db, $port)
or die("Unable to connect to MySQL");
I am new to php/sql and i have a login system which runs on my local host using xammp and it all works fine. I now want to upload it to my website but the code no longer works... I have created a sql db on my hosting service and tried to change the code.
the code that is used on the local host is
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "loginsystem";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
and this is the code that i have got from my hosting.
<?php
$host_name = 'db682827654.db.1and1.com';
$database = 'db682827654';
$user_name = 'dbo682827654';
$password = '<Enter your password here.>';
$conn = mysql_connect($host_name, $user_name, $password, $database);
if (mysql_errno()) {
die('<p>Failed to connect to MySQL: '.mysql_error().'</p>');
} else {
echo '<p>Connection to MySQL server successfully established.</p >';
}
?>
however this brings up an errror message. I have changed the password to the password for my database but its still not connecting.
This is the error message.
Failed to connect to MySQL: Access denied for user 'dbo706265806'#'217.160.62.78' (using password: YES)
Any help would be greatly appreciated
use mysqli_connect (not mysql_connect) like localhost:
<?php
$dbServername = "db682827654.db.1and1.com";
$dbUsername = "dbo682827654";
$dbPassword = "<Enter your password here.=)>";
$dbName = "db682827654";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>
On your computer you are using mysqli_connect, but on the server you are trying to use mysql_connect. Just use the same file from your computer and simply change $dbServername, $dbUsername, $dbPassword and $dbName to match those that your hosting provided.
I have a back end cron script that checks MySQl regurlarly for an if-then condition and then runs a Curl action. Anyway, the script has been running fine for over a year now when suddenly a problem occured and it does not make sense to me
here is the truncated code for the script
<?php
//assign values to variables
$servername = "localhost:3306";
$username = "username";
$password = "password";
$database = "database";
$con = mysqli_connect($servername, $username, $password, $database);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$results = "SELECT NewUserID FROM queue ORDER BY ID";
$queryresults = $con->query($results);
if($con->error) {
printf("Errormessage: %s\n", $con->error);
die();
}
I would see this error:
Warning: mysqli_connect(): (HY000/2002): Failed to parse address "localhost:3306:3306" in /home/foo/bar/BackEnd.php on line 11
Failed to connect to MySQL: Failed to parse address "localhost:3306:3306"
Fatal error: Uncaught Error: Call to a member function query() on boolean in /home/foo/bar/BackEnd.php:19
Stack trace:
#0 {main}
thrown in /home/foo/bar/BackEnd.php on line 19
The solution was simple, I change "localhost:3306" to "localhost" and everything worked again, since it seemed that ":3306" was being added to what was already there. This solution seems like a problem waiting to happen but im not sure what went wrong in the first place. Any ideas?
You can't specify the port in the host parameter.
Here is the full function definition:
mysqli_connect($host, $username, $password, $dbname, $port, $socket);
You should just add the port at the end of your call. Like this:
$con = mysqli_connect($servername, $username, $password, $database, 3306);
I am developing a login/register system for a website but when i'm trying to connect to the database it gives this error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\register.php on line 17
I'm using a external config file wich is been imported.
My config file:
// Connection details
$servername = "127.0.0.1";
$username = "root";
$password = "password";
$dbname = "database";
My connection code:
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
I found one solution that worked to connect but then my config file was useless.
No config but only this:
// Create connection
$conn = mysqli_connect('127.0.0.1', 'root', 'password', 'database');
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
If someone nows a solution where i can keep using my config file please post it here.
Thanks in advance.
Well, if the connection works with this values:
$conn = mysqli_connect('127.0.0.1', 'root', 'password', 'database');
But not with this values:
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "cloud";
Why don't you just set the "working" values into your config file. So it would look like this:
$servername = "127.0.0.1";
$username = "root";
$password = "password";
$dbname = "database";
Another solution which is described here includes the creation of a new user, so you don't connect via root, but the new created user.
I am getting this error:
Server Response='12154 ORA-12154: TNS:could not resolve the connect identifier specified
I am on Ubuntu 14.04
My environment variables are:
ORACLE_HOME = /usr/lib/oracle/12.1/client64
LD_LIBRARY_PATH = /usr/lib/oracle/12.1/client64/lib
TNS_ADMIN = /usr/lib/oracle/12.1/client64/network/admin
tnsnames.ora and sqlnet.ora are within /usr/lib/oracle/12.1/client64/network/admin
PS: I can connect through sqlplus with:
sqlplus64 user/pass#dbname
This is the code:
<?php
$conn = oci_connect('user', 'pass', 'dbname');
?>
It never worked on that way, what I did was to use Easy Connect string:
$conn = oci_connect('user', 'pass', 'host/servicename'); however the first way should have worked because in another environments it works.
tnsnames.ora file should look as follows
DBNAME=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCP)
(HOST=YOUR IP ADDRESS)
(PORT=YOUR PORT NUMBER)
)
(CONNECT_DATA=
(SERVICE_NAME=YOUR DBNAMEPROD)
)
)
conn.php file should look as follows
$USERNAME = "hr"; // Login Username
$PASSWORD = "hr"; // Login Passowrd
$DATABASE = "DBNAME"; // Connect string to connect to your database found in tnsnames.ora
$conn = oci_connect($USERNAME, $PASSWORD, $DATABASE);
if(!$conn){
echo "Your Connection Has an error";
}
else{
echo "Your Connection is Successful"
}