I am trying to build a homne server for studies on a raspberry pi 3.
I am just trying to connect to my raspberry database and php base to use my database on a HTML page.
I tried everything 9not apparently), to change several times my login, i tried with 'root' and create an other user and give all privileges etc, but nothing seem to work. I have all installed, php work just fine, i can reach my server with a domain name hosted by noip. the html and php content pop just fine.
I can even connect to my database via ssh.
But since few month i tried to make it work and i am desesperate, so if someone can help me ...
<?php
$db = mysqli_connect("mywebsite","root","myLogin","mydbName")
or die(mysqli_error($db));
?>
so i would just be able to make request on my database, i am just blocked on that step
$con=new mysqli("localhost","root","root_password","database_name");
Generally, root has no password so the connection should be like this
$con=new mysqli("localhost","root","","database_name");
Related
UPDATE:
I tried having my php file in windows and connect to the mysql server remotely in linux using the code below
mysql_connect('10.128.xx.xx', 'jflim', 'helloworld');
this works! but when i tried uploading the same php file in linux(server) and changing the connection string to
mysql_connect('localhost', 'root', '');
its not working.. its also not showing any error message. php codes are working fine without database connection. Im not sure what the problem is now. many thanks
If you upload the .php file in the server where the mysql server is running you should use 'localhost'. But if the script is located in another machine replace the 'localhost' with an ip address or url (www.example.com).
Apart from that, make sure you use the right username and pw.
I can connect to my localhost and get info from a local phpMyAdmin database.
Now I want from a php file, that is stored on my local computer, but now the php file refers me to go to an external website:
<?php
//mysql_connect('localhost','root','root');
mysql_connect("http://eternal website","username","password");
mysql_select_db("dlvplant_portret_v1");
$q=mysql_query("SELECT * FROM people WHERE voornaam LIKE '%%'");
//$q=mysql_query("SELECT * FROM people WHERE voornaam ='""'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
I tried the link and copy/paste the username and pass and I use the good website link. (the link brings me at the myPhpAdmin login from the server). So everything works and is filled in good. But when I try to connect with my android phone (from phone to local comp's php file) then the php file refers me to go to external webpage, but it says: Host is unknown
Is it even possible to go from local to external and back again?
You can connect to external MySQL hosts - but you do not use the HTTP protcol for it. And external access needs to be enabled on the MySQL server.
You should use plain ip address(xxx.xxx.xxx.xxx) or single "DOMAIN.SOMETHING" instead of "http://DOMAIN.SOMETHING"
mysql_connect("IPADDRESS","username","password");
I have to tell you guys first that I'm a newbie of web development but I just got an assignment to maintain website. I copy all important files on server and set my computer to be a localhost with MAMP. After I try to run page index.php on browser but it show me a result like "NO Connect Server". I dont get it why it show me like that. I has tested my localhost by create test.php to do something for testing like echo and it works fine.
Does anyone know how can I fix this problem?
Thanks,
regards
From what it looks like, there is no real way to tell what the real problem is. The only things I can think of are the usual ones: the MySQL server isn't actually running, the user name or password is wrong, or the user name isn't actually registered in the system. Sorry that I can't give more details, but you could find more information if you replace the NO connect Server with mysql_error() like this:
$db = mysql_connect('localhost','username','passwort') or die(mysql_error());
That will print out the error text when the script dies. With that information, you can start to decode what is actually going on.
Ok so I have a client that is trying to move half his site to another server...in this i still need to pull data from both databases. SO i have the new site and i need to do a mysql db query on the old site so i can include the old nav....but when i do
<?php include("http://www.othersite.com/includes/db.php"); ?>
<?php include("http://www.othersite.com/includes/nav.php"); ?>
I get
Warning: mysql_query(): Access denied for user 'www-data'#'localhost'
(using password: NO) in /vol/www/othersite.com/public_html/includes/nav.php
on line 223 Warning:
How do i access another db from the new site and not allow it to interfere with the new db connection
you can use:
$newLink = mysql_connect($host, $user, $password);
mysql_select_db($db, $newLink);
and the you should add the $newLink to your queries so it will not use the "old" database link connection, like:
mysql_query('SELECT * FROM USERS', $newLink);
Hope it helps
P.S. It'll be more easy if you put the code from db.php and nav.php
You'd need to show us the actual code used to connect to these dataases (with passwords blanked out). But even without it I can tell you that the remote server is NOT called localhost.
It seems you're including these files from the remote site. It won't work this way, since the code is still executed on local server.
You must also make sure, that the remote MySQL allows remote connections, and that there is a MySQL user account with appropriate privileges created.
See: http://dev.mysql.com/doc/refman/5.5/en/privilege-system.html
...in this i still need to pull data
from both databases.
Good luck with this!
The way I would do this:
Copy code to server #2
Adjust it to fetch data from server #1
Change DNS record from ip of server #1 to ip of server #2
Wait 1 day
Give blocking 'server maintenance' for 5 minutes on server #1
rsync db from server #2 to #1 / adjust server #2 to fetch data from itself
Remove 'server maintenance'
Sell server #1 on ebay and get boozed
NOTE:
Sure, if you are talking about some private host.. There are far more successful yet complicated mechanisms to do the same without putting server offline.
Load http://www.othersite.com/includes/db.php in your browser. You'll notice that you cannot see the PHP code: what you obtain is the output of the PHP code. That means than changing all your ìnclude constructs to point to a remote HTTP server will simply break your site since you'll no longer have access to the source code.
Now, answering to your question, if you want to connect to a remote database you must find wherever you have the DB password and change the data: localhost with the new server address, www-data with your new user, etc. However, you probably need to configure the remote MySQL server so it accepts external connections from your new server's IP address.
I have two servers on my local network - one a web frontend and the other a MySQL backend. I have a PHP script that looks like this:
<?php
error_reporting(-1);
echo "Connecting...\n";
$link = mysql_connect("192.168.1.15", "-----", "-----") or die(mysql_error());
echo "Communicating with the server...";
mysql_query("INSERT INTO .....
//More code down here...
?>
This script is called on my web frontend to connect to the backend server. When this script is accessed from the local network (i.e. when I open the page by going to http://192.168.1.14), the script outputs
Connecting...
Communicating with the server...
and a row is added to the database, as it should. However when I connect remotely (i.e. going to http://myDomainName.com/mysql_insert_script.php) from a connection not on the local network, all I see is:
Connecting...
No error messages follow, the script just cuts off, and no data is added to the database. When I place a second, 'proxy' script on the server that simply requires() the above script and then I access the proxy remotely, everything works fine. Below is the proxy script, so you can get a better idea of what works and what does not:
<?php
//this script makes it appear that the mysql_script is being viewed from the local network
//I exist on the web frontend at 192.168.1.14
require("http://192.168.1.15/mysql_insert_script.php");
?>
I am sorry if I can't provide any more information, but I am stumped. Any help would be appreciated.
Chris
P.S. - I have verified that the mysql server is accessible from external hosts on the local network, but I have a firewall that prevents connections from outside my network. I don't think this would matter, however, as the MySQL server and the PHP script connecting to it are both run on the local net.
you got wrong server name