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.
Related
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");
I have webpages mostly in PHP, ms sql database and IIS 7 server. Locally it works fine but now I'm trying to upload that to webserver using VPN and Filezilla. The problem is, what do I have to configure to get that working? On webserver there are two folders : one for webpages and one for database files. Do I have to change $host name, $username and $password in file_constants.php, or is there any other configurattions needs to be changed? Please help
I'v read instruction but there is only two lines about that, saying that I must refer to a datasource that tells the server which database to use.
You should change hostname, username, password and database into the values your hosting has given you.
I'm just getting started trying to set up a server/website and have run into what is probably a very basic issue. I'm getting a blank screen when I try to connect to my installed mysql server with a php script; e.g.
<html>
<body>
<script src="http://protovis-js.googlecode.com/svn/trunk/protovis-r3.1.js" type="text/javascript"></script>
<?php
echo "Connecting..."
$user="root";
$password="passwd";
$server="127.0.0.1";
mysql_connect($server,$user,$password);
echo "Connected.";
?>
</body></html>
shows "Connecting..." but never reaches "Connected". There's nothing wrong with the code or database, since this did work within the browser in Aptana 2.05 (since uninstalled). It doesn't work within Firefox or Chrome. Aptana was using a different (older) version of PHP, 5.2; phpinfo() accessed from Chrome/Firefox was 5.3. The php.ini file contains extension=mysql.so; otherwise I couldn't tell if the settings were correct or not. The tutorials I looked at didn't really cover this sort of thing... anybody know what to do?
What browser you're using has nothing to do with whether the php script running on the server connects to a database or not.
I would suggest checking the server logs, or adding some code to actually check and see what's going on:
$link = mysql_connect($server,$user,$password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
Your MySQL instance may be configured to not respond to localhost. There are two ways of connecting to a MySQL server; through a network connection (ip and port) or socket connection, which only works on the machine it's working on. Your MySQL server may be configured to listen to socket connections but not network.
Try connecting using the mysql command line tool as "mysql -h 127.0.0.1 -uroot -ppassword mysql"
Try running your PHP script from the command line instead of inside the browser.
Ha! Just didn't have the php5-mysql package installed. So evidently having php and mysql by themselves is not enough. Installed php5-mysql, the connection worked.
I have just moved my host to another machine but now a problem has occured. I get different mysql results from php. To be more spefecific, php returns the last result when i got back-up. I am checking database via mysql console but there are new entries. But php continues to return the old results. What do i need to do fix this?
P.S i can download php files which are on my new host. I can see the source code. Weird...
Thank you.
Your php might still be connecting to the old database
If you can download the php files, your server isn't set up to run PHP and/or has a mis-configured .htaccess file
Check your database connection code.
It's possible that you're connecting to a remote host, rather than 'localhost':
$mysql_connection = mysql_connect('mysql.example.com', 'user', 'pass');
There is another possibility, different databases:
mysql_select_db('using_old_db', $mysql_connection);
I have a script that uses ftp_connect() among other FTP PHP functions for uploading a file.
ftp_connect() works when executed on my local development server for connecting to a remote FTP server. The same script, when executed on the remote server does not work for connecting to the exact same FTP server.
Could somebody please point me in the right direction?
Thanks!
Here is the code:
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$server = 'ftp.someserver.com';
$ftpConn = ftp_connect($server);
if(!$ftpConn)
echo 'failed';
else
echo 'success';
No errors are reported.
So if I understand it correctly then the script above is installed on the server that you're trying to access using FTP (ie. the script is opening a local FTP connection)? What's the use? FTP in PHP is only useful to transfer files between 2 servers, you cannot use it to transfer files from the client to the server (since the script is executed on the server).
edit
Something I didn't add in my original comment : you could use a Java FTP applet if you want to transfer files from the client to the server. But be aware of the security issues involved (because the user credentials can be sniffed :p).
Probably firewall issues. On top of that, FTP was not designed with NAT in mind.
Try to login to the production server and use a ftp client to do the same connection.
I do not know the things inside it very well but I want to give my little help.My server is ubuntu Linux with Apache、PHP and MySQL,and my develop env is MAMP on Mac.
I met the problem suddenly and cannot find what happened because it was worked yesterday,I searched many answers and can't solved it.The ftp_connect($ftp_server) only return bool(false),but I can use my FileZilla,interesting,is it?
So I try to connect the server from my command line,like ftp 111.22.333.44,It shows:
500 OOPS: cannot read user list file:/etc/vsftpd/vsftpd.user_list
I login in my ubuntu server, and didn't find the vsftpd directory,and the vsftpd.user_listis in the directory /etc/,still don't know what happened.
So I simply create the directory and copy the file vsftpd.user_list to it.Then I try ftp 111.22.333.44(your IP address) again and it works now.
hope it help someone else.