Database login incorrect - mysql

I'm having some trouble with some software that I'm tweaking. During my install script I can type my database username, database name, localhost, etc and once I click next it is suppose to connect to the database and start the install. However when I click next I have shown this error:
Database Login Incorrect: config.php
Here is my config.php file:
<?php
// Mysql Settings
$mysqli_host = "";
$mysqli_login = "";
$mysqli_pass = "";
$mysqli_database = "";
$db_prefix = "";
$_dbConn = mysqli_connect($mysqli_host, $mysqli_login, $mysqli_pass)
or die ('Database Login Incorrect: config.php');
mysqli_select_db($mysqli_database, $_dbConn)
or die ('Unable to select the database: config.php');
?>
Although the database name and username are correct and have proper permissions. I can show the install file but it is over 2k lines and didn't want to post all of that :p
Thanks for your time!
Edit:
After using Geo V L's fix, I now have the error of "have you run install.php yet?". This is located in my structure.php file:
// Include functions...
include "scripts/php/functions.php";
// get board theme
$query2 = "select THEME from {$db_prefix}settings";
$result2 = mysqli_query($query2) or die("Have you run install.php yet?");
$theme = mysqli_result($result2, 0);

In this code snippent $_dbConn will be the first parameter for mysqli_select_db
<?php
// Mysql Settings
$mysqli_host = "";
$mysqli_login = "";
$mysqli_pass = "";
$mysqli_database = "";
$db_prefix = "";
$_dbConn = mysqli_connect($mysqli_host, $mysqli_login, $mysqli_pass)
or die ('Database Login Incorrect: config.php');
mysqli_select_db( $_dbConn,$mysqli_database)
or die ('Unable to select the database: config.php');
?>
Or you can directly add databasename on mysqli connect string like the following
<?php
// Create connection
$conn = mysqli_connect($mysqli_host, $mysqli_login, $mysqli_pass, $mysqli_database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>

Related

sql query to download BLOB Data from mysql database

I am looking for a way to load blob data from the table faq_attachment into a directory of my choice using a sql command in the MYSQL Workbench.
If necessary, the name can be composed of
file_id + filename Example: 61_image.png
I am unfortunately not a mysql expert…
thanks a lot
This is a very crude example but it should work. There is no graceful error handling or safety checks. It will overwrite existing files so make sure $file_path is writable and empty.
<?php
// Report all PHP errors
error_reporting(E_ALL);
$db_name = '';
$db_host = 'localhost';
$dsn = "mysql:dbname=$db_name;host=$db_host";
$user = '';
$password = '';
// the file path must be writable by the current user
$file_path = 'D:\\tmp\\';
// Creates a PDO instance representing a connection to a database
$PDO = new PDO($dsn, $user, $password);
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepares and executes an SQL statement and returns a PDOStatement object or false on failure.
$stmt = $PDO->query('SELECT `id`, `filename`, `content_type`, `content` FROM `faq_attachment`', PDO::FETCH_OBJ);
// iterates through the returned result set
foreach ($stmt as $file) {
// prepare filename with full path to write to
$filename = $file_path . str_replace(' ', '-', "{$file->id}_{$file->filename}");
// writes the content from the BLOB to the given file
file_put_contents($filename, $file->content);
}

Infinite Loading When Trying to Connect Into MySQL

I'm having a problem connecting to mysql database in XAMPP. It always takes time to load this segment of php code. What might be the problem?
<?php
session_start();
//redirect function
function returnheader($location){
$returnheader = header("location: $location");
return $returnheader;
}
$connection = mysqli_connect("localhost:85","root","") OR die(mysqli_error());
$db_select = mysqli_select_db("pts",$connection) OR die(mysqli_error());
$errors = array();
if(isset($_POST["iebugaround"])){
//lets fetch posted details
$uname = trim(htmlentities($_POST['uname']));
$passw = trim(htmlentities($_POST['psw']));
//check username is present
if(empty($uname)){
//let echo error message
$errors[] = "Please input a username";
}
//check password was present
if(empty($passw)){
//let echo error message
$errors[] = "Please input a password";
}
if(!$errors){
//encrypt the password
$passw = sha1($passw);
$salt = md5("userlogin");
$pepper = "ptsbtr";
$passencrypt = $salt . $passw . $pepper;
//find out if user and password are present
$query = "SELECT * FROM users WHERE username='".mysqli_real_escape_string($uname)."' AND password='".mysqli_real_escape_string($passencrypt)."'";
$result = mysqli_query($query) OR die(mysqli_error());
$result_num = mysqli_num_rows($result);
if($result_num > 0){
while($row = mysqli_fetch_array($result)){
$idsess = stripslashes($row["id"]);
$firstnamesess = stripslashes($row["firstname"]);
$username = stripslashes($row["username"]);
$_SESSION["SESS_USERID"] = $idsess;
$_SESSION["SESS_USERFIRSTNAME"] = $firstnamesess;
$_SESSION["SESS_USERNAME"] = $username;
setcookie("userloggedin", $username);
setcookie("userloggedin", $username, time()+43200); // expires in 1 hour
//success lets login to page
returnheader("users-area.php");
}
} else {
//tell there is no username etc
$errors[] = "Your username or password are incorrect";
}
}
} else {
$uname = "";
}
?>
And this is the error after loading it for minutes.
Warning: mysql_connect(): MySQL server has gone away in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10
Warning: mysql_connect(): Error while reading greeting packet. PID=6940 in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10
Warning: mysql_connect(): MySQL server has gone away in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10
(backstory: my Apache is also having a problem with localhost/127.0.0.1. It only appears blank page every time I try to access it with just localhost. So I always put the port every time I try to access it. I already removed all unnecessary port in hosts file. I already change the listen port of the httpd.conf and the Server name too with the port in it)
You can't add the port in "localhost:85", try it like this:
$connection = mysqli_connect("localhost","root","") OR die(mysqli_error());

Qt isOpen method false value MySQL

I have a MySQL database, which i created in Workbench. I can easily connect to it using php code:
<?php
$host = "localhost";
$port = 3306;
$socket = "";
$user = "hate";
$password = "88005553535";
$dbname = "galleries_db";
$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server' . mysqli_connect_error());
echo "DONE!";
?>
But when I'm trying to connect to my DB with Qt like this:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setPort(3306);
db.setDatabaseName("galleries_db");
db.setUserName("hate");
db.setPassword("88005553535");
db.open();
if(!db.isOpen()) {
ui->label->setText("-");
qDebug() << "Error: "<< db.lastError() << " " << db.lastError().text();
}
else
ui->label->setText("+");
I always get false value returned by isOpen method. And in stream I have:
Error: QSqlError("", "", "") " "
May be problem in MySQL driver for Qt ? Or there is something else ?
Will appriciate any help or advice.
There should be:
if(db.isOpen())
Not:
if(!db.isOpen())
Actually it is very silly mistake. isOpen always returned me true value, and I made it false by myself.

Warning: mysql_select_db() expects parameter 2 to be resource,

<?php
$servername = "localhost";
$username = "root";
$password = "Rachel";
$db = "hairdressingapointments";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected Sussessfully";
mysql_select_db('Hairdressingapointments', $conn) or die(mysql_error());
$sql = "SELECT `ApointmentDate`, `ApointmentTime` FROM `apointments` WHERE `staff_id`=1 && `quantity`>0";
if(!mysql_query($sql)){
die('Error: ' . mysql_error());
}
echo $sql;
mysql_close();
?>
spent hours trying to figure this out and im guessing its something so simple. getting back the following error:
Warning: mysql_select_db() expects parameter 2 to be resource, object given in C:\wamp2\www\hairdressingapointments\TeresaApointments.php on line 15 which is,
mysql_select_db('Hairdressingapointments', $conn) or die(mysql_error());
You already connected to the database using
mysqli_connect(...);
So, you do not need
mysql_select_db(....);
Also change the query to this
$sql = "SELECT ApointmentDate, ApointmentTime FROM apointments WHERE staff_id=1 AND quantity>0";
If you use SQLWorkbench or SQLYog or some other tool, you can enter your SQL and make sure it is valid before adding it to your script.
Also, make sure the table name is really
apointments
and not
appointments
I got this information from php.net - mysqli_connect

Getting 2 Notice: Undefined Variable errors

The two errors are as below:
Notice: Undefined variable: HawA_Homes in C:\wamp\www\HawA_CIS241\InsertRecord.php on line 48
Notice: Undefined variable: HawA_Homes in C:\wamp\www\HawA_CIS241\InsertRecord.php on line 56
I've checked my names and they appear correct and I am not sure how to proceed now.
Code is as below:
<?php
$hostName = "localhost";
$databaseName = "test";
$userName = "root";
$password = "";
$tableName = "HawA_Homes";
//try to connect report error if cannot
$db = new mysqli($hostName, $userName, $password, $databaseName) or die(" Could not connect:" . mysql_error());
print(" Connection successful to host $hostName <br /> <br />"); //report connection success
//Get data to create a new record
$Address = $_REQUEST["address"];
$DateBuilt = $_REQUEST["dateBuilt"];
$Value = $_REQUEST["value"];
$Size = $_REQUEST["size"];
$Number_of_floors = $_REQUEST["floors"];
$sql = "INSERT INTO $HawA_Homes('Address','DateBuilt','Value','Size','Number_of_floors')VALUES{'$Address','$DateBuilt','$Value','$Size','$Number_of_floors')"; //Create insert query for new record
//try to query dataase / store returned results and report error if not successful
if(!$result =$db->query($sql))
{
//die('There was an error running the query[' .$db->error . ']';
}
print("SQL query $sql successful to database: $HawA_Homes <br /><br />"); //report sql query successful.
?>
You have these notices because the variable $HawA_Homes isn't declared in your code before being used at line 48 and 56. (These are just notices, they are not critical errors, you can avoid displaying them by adding error_reporting(E_ALL & ~E_NOTICE); at the begining of your code, like explained here)
In fact, you used $HawA_Homes instead of $tableName in these lines. Replace them, you won't have notices anymore for these lines.