Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
I tried to access the database on IP 192.168.1.102 using Raspberry PI that have IP 192.168.1.129.
this is my code on constans.php
<?php
// Database Constants
//define("DB_SERVER", "127.0.0.1");
define("DB_SERVER", "192.168.1.102");
define("DB_USER", "aas");
define("DB_PASS", "aas");
define("DB_NAME", "db_adis_2");
?>
And this is my code on connection.php
<?php
require ("constants.php");
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
error_log(mysql_error() . "\n", 3, "my-errors.log");
}
// 2. Select a database to use
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
error_log(mysql_error() . "\n", 3, "my-errors.log");
}
?>
But i keep getting the error
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.
Here is my XAMPP on 192.168.1.102
Xampp
That makes me confuse because when i try to connect it to different IP (192.168.1.5) with the same DB, it came out successfully. So where did i do wrong? or there is anything extra that i should do?
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm working on a larger Project that installs a php interpreter via xampp and mariaDB together with a larger project, containing a database and some php files on a blank windows 10 system.
i got everything running so far, the php server is running on command and the mariadb server seems to be reachable too.
The problem I'm facing lies in the fact that our project (which works perfectly under phpstorm and via command line on ANOTHER SYSTEM) doesn't seem retrieve the table data of our database in this VM.
The connection from inside the php is working and the database itself gets recognized too. I checked that by printing it like this:
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "toor";
$dbname = "emensawerbeseite";
$dbport = "42069";
$link= mysqli_connect ($dbhost, $dbuser, $dbpass,$dbname,$dbport);
if(! $link ) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully</br>';
$link->set_charset("utf8"); //enables the good old äüö's
$db_list = mysqli_query($link, "SHOW DATABASES"); //mysqli
while ($row = mysqli_fetch_object($db_list)) {
echo $row->Database . "</br>";
}
this prints me this output:
I can also list the all table column names.
The database itself I just Copied in the data folder of mariadb.
It persists of the same .frm and .ibd and .opt file(s), that my working version has.
Problem lies when i try to insert or retrieve any sort of actual data from the database e.g. like this.
$sql2 = "insert into gericht (id, name, beschreibung, erfasst_am, vegetarisch, vegan, preis_intern, preis_extern) values (22, 'CCurrywurst mit Pommes', '', '2022-11-14', false, false, 4.20, 6.90)";
if ($link->query($sql2) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql2 . "<br>" . $link->error;
}
Which is when the the following Error appears:
"Fatal error: Uncaught mysqli_sql_exception: Table 'emensawerbeseite.gericht' doesn't exist in engine in C:\xampp\php\index.php:43 Stack trace: #0 C:\xampp\php\index.php(43): mysqli->query('insert into ger...') #1 {main} thrown in C:\xampp\php\index.php on line 43"
What does this actually mean?
And what could i do about it?
Some Posts suggested to just restart or other things that didn't work.
"Table 'emensawerbeseite.gericht' doesn't exist in engine"
This means that your database is corrupted. In case of InnoDB the dictionary (ibdata1) doesn't contain information about table gericht or is missing at all.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm making a website that uses SQL and PHP functionalities. How do I connect to a database?
I would advise you begin by looking here.
You need to ensure that you have created user credentials with the correct permissions to query the database before you try this. You can do this through the cPanel of your web server (I'm going to assume you are using a web hosted server for this question).
Once you have a working and tested connection to the database, you can then start looking at the mySQLi documentation here. Which will show you how to execute and retrieve results from a database query and how to handle the returned data with PHP.
I see you are seriously downvoted.
I learned it the hard way and I am still learning to post here.
Stack sites are supposed to be searched first. If your question is already answered then people downvote you.
The solution to your question:
In your mysql or phpmyadmin you can set whether you use a password or not. The best way to learn is to set mysql with a password in my opinion. If you will launch a website online finally, you have to take security measures anyway.
If you make contact to your mysql database with you have to set:
username, password, database and servername ( for instance localhost).
The most secure way is using the OOP / prepared method:
$servername ='localhost';
$username='yourname';
$password='12345';
$dbname='name_database';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($stmt = $conn->prepare("SELECT idnum, col2, col FROM `your_table` WHERE idnum ='5' ")) {
$stmt->execute();
$res = $stmt->get_result();
$qrow = mysqli_num_rows($res);
while ($row = mysqli_fetch_assoc($res)) {
var_dump($qrows); // number of rows you have
$total = implode(" / " , $row);
var_dump($total);
$idnum = $row['idnum'];
var_dump($idnum);
}
The easiest way that I do with my site is make a file called db.php containing:
<?php
$host = 'localhost';
$user = 'root';
$pass = 'password';
$db = 'databasename';
$mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);
..then in the index.php file, at the top:
<?php
require_once('db.php')
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
preface
I am setting up a web environment intended to be hosted on a local server strictly accessible on the local network. There's about 50 employees within the office and no employee has an assigned computer.
problem
Via an HTML form with parameters ('host', 'username', 'password'), the PHP will attempt an ssh.
Main Point
Basically I'm trying to find out how to interact with ssh from PHP (i.e. edit and view files/directories.
ie
user enters username, password into an html form. My php code takes this information and (if valid) ssh into their user on server. Giving them access to directories and files.
You can use phpseclib to handle the SSH. Here is some simple code to get you started:
<div>
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('Net/SSH2.php');
function display_home_directory($hostname, $username, $password) {
$ssh = new Net_SSH2($hostname);
if (!$ssh->login($username, $password)) {
echo 'Login Failed';
}
echo '<pre>';
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
echo '</pre>';
}
display_home_directory('example.com', 'myusername', 'mypassword');
?>
</div>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have been trying to connect to a mysql database many different ways but no matter how I do it I get an error. I'm pretty new to php so it might be my mistake but I would appreciate any help.
<?php
$servername = "localhost";
$username = "xyz";
$password = "1234567";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
All of the information is correct but it returns Connection failed: Access denied for user 'xyz'#'localhost' (using password: YES)
mysqli_connect($serverName,$Username,$Password,$Database);
Try appending your database name to the final parameter
Solutions:
Have you granted your user access to the database schema?
Have you ensured you're using the correct password/user?
Have you ensured your server name is correct? (Not localhost,
possibly an external IP?)
A possible solution would be try the server IP, as DNS can sometimes fail. Incase you was unaware, localhost IP is 127.0.0.1
Put localhost into quotes:
mysql_connect('localhost',$username,$password);
The error message Access denied for user 'xyz'#'localhost' (using password: YES) is an indication that either the password is wrong or the user xyz has not been installed as descibed in the manual: https://dev.mysql.com/doc/refman/5.6/en/adding-users.html
The username and password you specified is not registered as a database administrator.... the default username is root and password is blank
basically you did not set up permission correctly, double check host.
run
select user,host from mysql.user;
to check what is host address you provided
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a function that handles my db connection. In casse my main DB isn't available I want to use a backup one.
I tried to do so using below code but it's not working...
$host = 'xxx';
$database = 'xxx';
$login = 'xxx';
$pass = 'xxx';
if (! mysql_connect( $host, $login, $pass ) )
{
// try to connect to backup db
$host = 'yyy';
$database = 'yyy';
$login = 'yyy';
$pass = 'yyy';
mysql_connect ( $host, $login, $pass ) or die ( "Failed to connect to the database: " . mysql_error());
}
mysql_select_db ( $database ) or die ( "Failed to find the database" . mysql_error());
mysql_query("SET NAMES 'utf8'");
I'm sure about my connection parameters, so the problem isn't there
Edit:
I'm using an old version of php so I'm limited to Mysql_*
My 1st server is currently down, and I'm getting a 'Warning: mysql_connect() [function.mysql-connect]: Too many connections in ...' error
In fact my problem is that I need NOT to print this warning message if the 1st connection failed...
Please note Mysql_* is deprecated, use mysqli_ or PDO which is far more secure.
Have you tried outputting the error? I don't see it in your code.
I haven't used mysql_ for a long time, but try outputting the error using:* mysql_error()
As mentioned, it could be a variety of problems:
Mysql isn't started
Firewall is blocking the connection
Not using default port
...
Edit:
Also you may want to look into setting up replecation for such events as DB failure.
Don't do this in your code, just use something like MySQL Proxy to do it for you.
When php fails to connect, it generates a warning, which stops the php execution.
You may use #mysql_connect (function name prefixed with an "#") to avoid the warning. And your code will continue to execute, even if first sql server does not respond. crappy, but working.