So i'm getting this warning and i have no clue how to fix it. Its for my connect file to my database.
Warning: require(includes/connect.inc.php): failed to open stream: No such file or directory in /customers/5/e/6/gixter.dk/httpd.www/index.php on line 4 Fatal error: require(): Failed opening required 'includes/connect.inc.php' (include_path='.:/usr/share/php') in /customers/5/e/6/gixter.dk/httpd.www/index.php on line 4
My connect file look like this:
<?php
$conn_error = 'Cound not connect to database.';
$mysql_host = 'xxxxx';
$mysql_user = 'xxxxx';
$mysql_pass = 'xxxxx';
$mysql_db = 'xxxxx';
if (!#mysql_connect($mysql_host, $mysql_user, $mysql_pass) or !#mysql_select_db($mysql_db)){
die($conn_error);
}
?>
Can anyone help?
The path you specified is incorrect. The file doesn't exists or can not be found in the folder. It might be on a higher level. (../)
The mysql extension is no longer supported, please take a look at the mysql_i extension or PDO. Mysql is deprecated and vulnerable to SQL-injection.
Mysql_i
PDO
Related
I am trying to connect to my MySQL version 8.0.11 database in zend server version 7.2.10 using php but I could not connect it
Warning: mysqli::__construct(): Unexpected server respose while doing caching_sha2 auth: 109 in C:\Program Files (x86)\Zend\Apache24\htdocs\connectdatabase.php on line 7
Warning: mysqli::__construct(): MySQL server has gone away in C:\Program Files (x86)\Zend\Apache24\htdocs\connectdatabase.php on line 7
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in C:\Program Files (x86)\Zend\Apache24\htdocs\connectdatabase.php on line 7
Connection failed :MySQL server has gone away
I am getting the following warnings when i try to run my code.
i have searched and tried ALTER USER 'username'#'hostname' IDENTIFIED WITH mysql_native_password BY "userpassword" command but it does not work for me
<?php
$servername = "localhost";
$username = "root";
$password = "hello";
$conn = new mysqli($servername,$username,$password);
if(mysqli_connect_error())
{
die("Connection failed :" . mysqli_connect_error());
}
echo "CONNECTED SUCCESSFULLY";
?>
Try with caching_sha2_password:
ALTER USER 'username'#'hostname'IDENTIFIED WITH caching_sha2_password BY 'userpassword';
I'm trying to connect to a remote sql server database via php in our debian server.
<?php
// Some basic variables
$Server = "myservername";
$User = "myuser";
$Password = "mypwd";
$Database = "facts_sql";
// Connect to the database
$dbconnect = mssql_connect($Server,$User,$Password);
?>
And I got the error.
PHP Warning: mssql_connect(): message: Login failed for user ''. (severity 14) in /var/www/Information.php on line 8
PHP Warning: mssql_connect(): General SQL Server error: Check messages from the SQL Server (severity 14) in /var/www/Information.php on line 8
PHP Warning: mssql_connect(): Unable to connect to server: myservername:1433 in /var/www/Information.php on line 8
Are there any advices? Thanks
$db= mysqli_connect('localhost', "root", "root");
if(!$db) die("Error connecting to MySQL database.");
mysqli_select_db("onlineform", $db);
As I try to connect to the database like shown above, I am getting the following error:
Warning: mysqli_connect(): [2002] No such file or directory (trying to connect
via unix:///var/mysql/mysql.sock) in - on line 3 Warning: mysqli_connect():
(HY000/2002): No such file or directory in - on line 3 Error connecting
to MySQL database.
It's my first time using mysqli, I thought it would be a big improvement over mysql. I checked with MAMP if it's enabled and it is.
Any suggestions?
Check if your socket is correct. If not, override the default socket. I guess you have to try something like this in MAMP:
$link = mysql_connect(
':/Applications/MAMP/tmp/mysql/mysql.sock',
'root',
'root'
);
I have a snippet of code under the PHP file in Eclipse PHP.
$username = mysql_real_escape_string( $username );
It generates an error Warning:
mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /web_development/php_work/new_test/test.php on line 37
Looks like the Eclipse PHP couldn't connect to the MySQL of XAMPP, so How do I fix that?
I added two lines
#mysql_connect('localhost','root', '') or die('Could not connect to : ' . mysql_error());
#mysql_select_db('test') or die( "-Unable to select database");
but Eclipse still throws me.
mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to local MySQL server through socket '/tmp/mysql.sock'
thx.
I'm having some problems while trying to connect a .php with mysql.
here's the connection.php code
<?php
$db_host =$_POST['localhost'];
$db_user =$_POST['root'];
$db_password = "";
$db_name = "prtcl";
?>
and this is the page where I actually use the connection
<?
include("connection.php");
?>
...
<?php
$db = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $db);
if (!$db)
{
die('Could not connect: ' . mysql_error());
}
mysql_close($db);
?>
<body>
...
that's what I get when I try to load it ( line 29 is this one:
$db = mysql_connect($db_host,
$db_user, $db_password);
)
Notice: Undefined variable: db_host in
C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Notice: Undefined variable: db_user in
C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Notice: Undefined variable:
db_password in C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Warning: mysql_connect()
[function.mysql-connect]: [2002] A
connection attempt failed because the
connected party did not (trying to
connect via tcp://localhost:3306) in
C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Warning: mysql_connect()
[function.mysql-connect]: A connection
attempt failed because the connected
party did not properly respond after a
period of time, or established
connection failed because connected
host has failed to respond. in
C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Fatal error: Maximum execution time of
30 seconds exceeded in C:\Program
Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
as you can see I'm using EasyPHP and, since this very code used to work before (with a different db, while using manually configured apache/mysql), may be that the reason? Other infos: I made the db using phpmyadmin and I have win7
thank you
Don't ever take your db credentials from $_POST without validation. This is such a terrible idea and this is what's causing your errors, as these keys are not being defined in $_POST, but they could be and the results could be disastrous!
try putting this in connect.php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "prtcl";
$db = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $db);
if(!$db) {
die('Could not connect: ' . mysql_error());
}
then in your other pages use:
require_once("path/to/connect.php");
// ... whatever else you do on this page...
I would find out why the $db_host variable is not getting defined. That might be a problem with your form input. Check to see that the name of that input field really is 'localhost'. Also, as Mark Baker mentioned above, you really want to do some input cleansing to guard against sql injection attacks. Plus, is there any reason you can't hardcode the db host info into a configuration file?