PHP ftp_connect() fail - php

Very simple problem but one which I am unable to solve. Why would I get a ftp_connect() fail?
$conn = ftp_connect("www.server.com");
Have tried SSL connect. Intrestingly I had no problem with this ftp_connect() on this server until recently when I started getting error messages. Not too sure what triggered this perhaps an update as the code was not altered.
Thanks in advance
Edit: Found this in Plesk : Shell access to server with FTP user's credentials - ForbiddenHave no idea if its relevant

Ok, after lots of fiddling (asking someone else) this is the solution I found...
$conn = ftp_connect(localhost);
Well the simplest solution is the best. This works as the code is situated on the server to which it is trying to connect.

Related

phpGrid "Error: Could not connect to the database" debugging

I have implemented a phpGrid that works in my dev environment but just keeps saying:
Error: Could not connect to the database
in production
I am logging failed attempts at MySQL connections in the logs on and if I put in a dodgy username and password in the conf.php files username/password it does not show up in the log (I've tested the log is working by attempting to connect with bad credentials via a terminal.
The host is just "localhost" I am using PDO connections elsewhere within my code and the are all connecting using "localhost" so I see now reason why this would be a problem.
In the conf.php I've turned on:
define('DEBUG', true);
And on my grid I have:
$dg -> enable_debug(true);
But I just keep getting this stupid error that tells me nothing about what's really going on...
It happened to me as well. Finally I was able to figure out. The reason is mySQLi was not enabled on the server. I enabled it and it works now.
Sorry, i cannot add a commant and sorry for my english.
If you are using PHP 5.5 try:
error_reporting=E_ALL^E_DEPRECATED
at top of the page for the time being.
For the files on your production machine: proof if they are still in utf-8 encoding

How to use SQLyogTunnel_ciom.php

I am working with mysql credentials where I always get an error : access denied for root#user
I have ssh details so I used heidisql and sqlyog to connect to database, It worked.
Now I have to write code for this database using php.
mysqli_connect gives the same error.
I searched and tried many things (like using ssh -fNg -L) but non of them worked for me then some how I got a file 'SQLyogTunnel_ciom.php'
but I have no idea how to use it. I tried to include it and call its function but that is not working either.
Kindly suggest me how to work around in this situation.
http://blog.webyog.com/2012/10/31/think-beyond-phpmyadmin-to-access-mysql-on-a-shared-host/
This blog post explains how you can create something like SQLyogTunnel.php to access database in a shared hosting.

Kohana/php Headers and client library minor version mismatch

I have come to a very strange error, and as the title says i get:
mysql_connect(): Headers and client library minor version mismatch. Headers:50095 Library:50149
After some googling i found out that it might be caused by wrong mysql/php version, well that might be right, but the thing is i am using php framework kohana and if try to run this very simple connect code without that framework:
$sql = mysql_connect("server", "root", "passowrd") or die(mysql_error());
mysql_select_db("db", $sql);
It works just fine, so my guess is that this error is caused by php script somewhere, could it be possible? And if so, can i fix it without updating server, because it's not really possible since i'm using public rented host.
Also just in case here is the class which connects to DB: http://pastebin.com/VFtj0re6
P.S i have tried to remove all code from public function connect() function, and add my own connection code which seems to be working, but it did not help.

ERR_CONNECTION_RESET Error using WAMP

I have installed WAMP on my system. My localhost site works properly, but when I pass something in the URL like http://localhost/test.php?a=1 I get error like "Error 101 net ERR_CONNECTION_RESET".
Has any one experienced this same error or have a solution?
If you are trying to interface to MySQL it may be an issue with the driver...
https://serverfault.com/questions/74313/what-could-cause-an-101-error-in-wamp-under-windows-7
Check your logs to see what exactly is causing the error...
Are you sure that it is WAMP's error? I googled your error and found this: http://www.google.com/support/forum/p/Chrome/thread?tid=476f762a0f84017f&hl=en
#pradeep even I had the same problem. You should close the connection at the end of your page code using the connection resource. worked for me ... mysql_close($conn); where $conn is your mysql database connection resource variable which you have used to connect to mysql database.
Faced the same problem with WampServer 2.1 ; and basically resolved it by installing latest version of WampServer (WampServer 2.2D).

Confusing PDO-only problem : Can't connect through socket/Access denied/Can't connect to server (shared host)

So the problem changed from what it was, i'll leave the original question below to prevent bad reviews on answers like I had after someone editing his question I answered :
So I am working on a (really lame) shared hosting which has PDO installed, but it doesn't work.
With default parameters
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
it throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
With a simple mysql_connect, it works.
And the socket path seems correct (both phpinfo and this query :
show variables like 'socket';
confirm.
Localhost redirects to 10.103.0.14 (this data comes from mysql_get_host_info() and in phpMyAdmin)
In the PDO, if i replace localhost by 127.0.0.1 i will get
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)
And if i replace localhost by 10.103.0.14 :
Access denied for user 'USER_NAME'#'10.103.0.14' (using password: YES
Both IP adress (127.0.0.1 and 10.103.0.14) work with mysql_connect.
So apparently the problem comes from the PDO connection.
Does somebody knows where this could come from, or/and any way to fix it ?
Some server datas :
The PHP Version : 5.2.10
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
No command line possible.
(i know it should be the tech suport's job, but they're reaaaaaly slow)
Thanks
Previous question :
How to find the mysql.sock on a shared host (tricky way needed...)
So today's problem is : The PDO connection doesn't work on a shared host, and it's supposed to (it's installed on the server).
Just a basic PDO connection :
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
A regular mysql connection :
mysql_connect("localhost", "THE_USER", "THE_PWD") or die(mysql_error());
mysql_select_db("24DLJLRR1") or die(mysql_error());;
echo 'Connected to database <br/>';
works fine.
So apparently it cannot find the .sock.
I think specifying the correct address should work, i tried some "classic" mysql path that I found on internet, without success.
The phpinfo says it is at this adress (/var/lib/mysql/mysql.sock)
(The PHP Version is 5.2.10)
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
So i am trying to figure out where the hell it is !!!
I tried to look in the phpMyAdmin interface, but i couldn't find the info, plus it seems that phpMyAdmin connects to a different server (it has a different IP adress, and trying to connect to it with php gives a "Wrong password" error). The mysql_connect also connects to this adress, i think it redirects to a different server with some internal password/login.
Well if you have any idea of how to obtain this info (the provider's technical support is "fixing the problem"... it's been 1 month...).
Also maybe the problem comes from somewhere else, but the same stuff works on other shared hosts...
The need of PDO is because I use the Symfony framework with Doctrine for this website, and the Doctrine plugin needs PDO... I don't want to redo the website from scratch !
Thanks for your help !
This was already marked as answered, but not really solved (without changing databases).
So, just in case someone like me also experiences this problem...
The easiest way to fix this is to first get the socket path (either by looking in the php.ini file or by using: phpmyadmin or the console (or construct it in mysql or mysqli)
...to run the following query (anything but PDO):
show variables like 'socket'; //as mentioned by symcbean
THEN, in the PDO connection string, change it to use the socket instead of a hostname:
$dbc = new
PDO("mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=$DBName",
$User, $Password, array(PDO::ATTR_PERSISTENT => true)); // using
persistent connections
This worked for me.
FWIW, I had this issue and changed my host from 'localhost' to '127.0.0.1'.
I have no clue why localhost wasn't working, but that did the trick.
Odd thing is, we have tons of servers and it works on almost every one using 'localhost'
Is your server running with SeLinux enabled (enforcing)? If it is, try running as root:
# setsebool -P httpd_can_network_connect on
Can you try 127.0.0.1 as the server name instead of localhost?
IIRC, with some mySQL drivers / adapters, this decides whether the socket is used for establishing the connection or not.
Using the connection which works, run the query:
show variables like 'socket';
(this behaves just like a select statement)...and you'll get the path of the running socket.
Then check the file permissions.
I had the problem that production version worked just fine and a test version wasn't able to connect PDO :/
both versions was located at same servers, test in a sub directory.
The fix was replacing in DSN the localhost for ip.
'mysql:host=localhost;dbname=db'
became
'mysql:host=127.0.0.1;dbname=db'
try:
exec('`which mysql_config` --socket');
this should show you the configured socket.
I found the reason for the strange behaviour. If bind-address is different to 127.0.0.1 or 0.0.0.0 (all addresses) PDO can't connect to 127.0.0.1.
For what it's worth, I found this page after having the exact same issue. I am on a server running Apache & PHP only - MySQL is installed on another machine. I tried both the DNS name of the server and its IP and confirmed I could ping it. A PHP app on the same machine is talking to the database fine, using old syntax mysql_connect( ). But PDO from the CLI was throwing this error.
The solution for me was to check my DSN. Any typo in the DSN itself is ignored silently, and PDO assumes you mean localhost. My issue was I had "name=" instead of "dbname=" in the DSN.
The Issue In the Mysql configuration It you need to disable the option of skip-networking
in my.conf configuration file this should work fine
reference
http://www.wolfcms.org/forum/post7098.html#p7098
I just solved a similar issue. My guess is you probably replaced your mysql_connect() statement with the PDO equivalent. Don't forget you still have lots of other code dependent on that old connection statement. Try keeping the mysql_connect in place while writing in the PDO code.
What worked for me was specifying the port number like so:
mysql:hostname;port=3306;dbname=dbname;
This got it to work when connecting to a local database. Now I'm working on getting it to work with a remote db.
My problem may be different to the OP, but I thought it was worth posting. I did a software upgrade on a VM, then rebooted and got the OP's error message. It turned out to be an out-of-memory problem preventing mysql from starting. Deleting a few large files made the problem go away.
One year later, I found a solution for this issue : using a SQLite database. PDO worked fine, but not with MySQL
** EDIT ** as everyone is downvoting this: This solved my issue (I'm the OP). I was using Doctrine, so switching RDBMS was easy and quick. Also the website was some a home made CMS, with very few trafic, so SQLite was fine.
I know it's not a real "Answer" to the problem, but if someone is in the same context: a crappy shared hosting which you can't change with this weird PDO-MySQL bug AND is using doctrine. This IS a solution. I can delete this answer, but if I had thought of this at the time of the OP, I would have saved a lot of time.

Categories