How can I access neo4j running on my local Mac from server - php

I have neo4j running on my localhost port 7474 on MAC and I would like to access the same from server http://www.example.com/test/
How can I do that? I tried adding IP on remote mysql in cpanel on server and its not working. Is there any other setting I should do/add on MAC ?
php code:
<?php
// connect
$cs = mysql_connect ( '123.123.123.123:7474', '', '' ) or die ( 'Can not connect to server' );
?>
error:
PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on '123.123.123.123' on line 4
also:
$link = mysqli_connect("123.123.123.123:7474","","","") or die("Error " . mysqli_error($link));
Error:
Unknown MySQL server host
mysqli_error() expects parameter 1 to be mysqli, boolean given

neo4j is not mysql, and cannot be accessed through a mysql driver.
Visit this URL for more information on accessing neo4j from PHP:
http://neo4j.com/developer/php/
You can test access using the neo4j-shell as well, if you have SSH access to your remote server:
http://neo4j.com/docs/stable/shell-starting.html
Also, if you want to access neo4j running on your local Mac from a server hosted in some datacenter somewhere, you'll need to make sure you can route the traffic to your local Mac. It seems like you've figured out how to do that (based on the MySQL errors).
For the reference of others, you'll need to adjust conf/neo4j-server.properties to reference 'org.neo4j.server.webserver.address=0.0.0.0'. This will make sure that neo4j binds to all IP addresses on the local box and not just 127.0.0.1. Additionally, if your Mac is behind NAT (network address translation), then your IP address will not be directly Internet-accessible (ie, if it's something like 192.168.1.12). In this case, you'll want to do port mapping on your router to map your real IP address:7474 to 192.168.1.12:7474, and then connect to your real IP address:7474 when accessing from an external server.

you cannot pass $link as argument for mysqli_error because it's not defined yet
$link = mysqli_connect(...) or die("Error " . mysqli_error($link));
proper way is e.g:
$link = mysqli_connect(...);
if ($link->connect_errno) {
die("Error " . mysqli_error($link));
}
I don't know if neo4j is running as MySQL server, than probably you need other database driver for PHP

Related

Error 500 ( Fatal Error ) using pg_connect() in php

im trying to use pg_connect to access postgres on another server,,
i did opened the remote access and i can use bash to connect to my postgres server ! and i did host all all client_ip/32 trust in config but when im trying to use pg_connect i get error 500 !
pgsql is also installed and i've checked it with function_exists('pg_connect') and i returns true !
my code is :
$dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB user=postgres") or die("Could not connect");
i've also tried this and get fatal error 500 again
$dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB
user=another_super_user_i_made password=user_password") or die("Could not connect");
what is the problem ?
when you are able to connect to a server from one machine on your network, but get a connection timed out issue from another machine, it usually is due to one of a few things.
1) DNS. The machine you are testing from (the "remote access" as you call it) is able to resolve the DNS name and the webserver running your PHP code is not. You can use actual IP address instead of DNS names to test this.
2) Connectivity. Different machines are connected in different ways in a network. If you are able to get to an IP from the "remote access" machine but the web server is having trouble connecting to it (with "connection timed out"), try connecting directly to that web server (using "remote access" like SSH) and see if you can connect manually from there.
If it's not a network related issue it could be an issue with your default PG timeouts. Try setting them manually with the connect string. Specifically, the "connect_timeout" option, like this:
$d=pg_connect('host=example.com user=pgsql dbname=postgres connect_timeout=5');
There was host blocking issue !
my client hosting was not enabling remote access to DB !
you should check with your hosting that they can trace your problem

PHP, can't connect to the MySQL server

What might be the reason of the following problem.
PHP function mysql_connect() works fine if I execute it from
command line (php -r "mysql_connect('127.0.0.1', 'db_user', 'db_pass');").
The same call with the same parameters fails for PHP running as an Apache module.
MySQL server is running remotely, connection to it is forwarded using SSH: ssh -fN -L 3306:localhost:3306 remote_host
Any ideas what might be wrong?
You'll want to be looking at using MySQLi or PDO as the older MySQL functions are deprecated.
This should help get you started:
<?php
//establish conection
$link = mysqli_connect("host","user","pass","bd") or die("Error: " . mysqli_error($link));
$query = "SELECT name FROM mytable" or die("Error: " . mysqli_error($link));
//execute query
$result = $link->query($query);
//display information
while($row = mysqli_fecth_array($result)) {
echo $row["name"] . "<br>";
}
?>
Based on your question and details, I would say that the MySQL server is refusing to connect to your web server (where ever it is) because the connection is not secure (in one fashion or another). If you want to connect via the PHP module in Apache as easily as you do from the command line, set up your connection so that all encryption/ tunneling issues are resolved. That's what I would do.
However, make sure the following line is correct..
mysql_connect('127.0.0.1', 'db_user', 'db_pass');"
Are you pointing to the correct server? I thought you said that the MySQL server was remote. This line suggests that you are attempting to connect to a local, imaginary MySQL server that is running on the same machine as the web server. Try getting the IP or domain name of the MySQL server and use that instead (in your web code, that is).

remote mssql 2008 connection issue

I am having issues connecting to a mssql server that is located on a network machine. I need to connect remotely through another domain example (abc.com) not on the network to access data. This domain runs mysql if that makes any difference. I am trying to access the mssql server through this php script:
<?php
$server= 'ip address:port';
$user='user';
$password= 'pass';
$con = mssql_connect($server,$user,$password);
if (!$con)
{
die('Could not connect:' . mssql_get_last_message() );
}
else{ echo 'connected';
}
I run this script through the shell on abc.com and I get:
mssql_connect(): Unable to connect to server:
I have gone through several tutorials to enabling tcp/ip access through the sql server config manager as well as allowing the specific port through the firewall.
What are some other things I should try or steps I am missing here.
Also: the ip address I am using is the one I found in the sql server config manager-> protocols for SQLEXPRESS->tcp/ip_>ip addresses->IP2->ip adress it is the correct ip address? Where can I find it if not? I am not using the localhost 127.0.0.1
In short to successfully execute the cmd.
config:
(2 instances of SQL // SQL2005 + 2008 Express instance on the remote machine, which refuses to install Management Studio 2008.
1. Enable TCP/IP Protocol
2. Enable Named Piptes
3. started sqlcmd Utility with -s \SQLEXPRESS to get the right sever-instance
C:\Program Files\Microsoft SQL Server\100\Tools\Binn
4. Go to SMSS and local sql instance properties -> Connections -> check "Allow remote connections to this server" and run this script.
EXEC sys.sp_configure N'remote access', N'1'
GO
RECONFIGURE WITH OVERRIDE
GO
Here the link for the info from Msdn:
http://msdn.microsoft.com/en-us/library/ms162773.aspx
http://msdn.microsoft.com/en-us/library/ms162816.aspx
Thanx

Why am I getting mysql_connect(): Lost connection to MySQL server and how can I fix it?

My php code fails to connect to the mysql database on my web server. I get the following error:
mysql_connect(): Lost connection to MySQL server at 'reading initial
communication packet', system error: 110 in filename at line 71.
The same code works fine when run from my development machine pointed at the mysql database on the server I'm trying to run this from (I copied the file up to the server and I'm trying to run it via ssh on that server). I have verified that the mysql user in the script can connect to the database from the server by running mysql from the ssh command line on that server using the same user name and password as specified in my php script.
here is my code:
function jsw_set_cnxn($env){
global $env;
$cnxn = mysql_connect($env['db_svr'], $env['db_usr'], $env['db_pwd'])
or die ('DB Connection Error: ' . mysql_error());
mysql_select_db ($env['db'], $cnxn);
return $cnxn;
}
I've seen this error caused when using the servers IP address when it expects localhost as the server address.
This is because the server is the machine mysql expects but the wrong host coming in. Try using localhost.

mysql_connect doesn't work on a certain host

I get this everytime I use mysql_connect() no matter what database I choose:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'IP' (111) in filename.php on line 17
A MySQL error has occurred: Can't connect to MySQL server on 'IP' (111)
The exact same file works on my personal website fine. I have tried multiple databases hosted on different servers and it always gives that output.
The database itself is hosted on the same server, but using its full IP in mysql_connect(). Using localhost:port doesn't work either as it says:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in filename.php on line 17
A MySQL error has occurred: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
But using the IP should work as it has worked calling it via the same file hosted on other servers.
This is the code:
$connect = mysql_connect($db_url,$db_user,$db_pass); // connects
if ($connect == false) exit("A MySQL error has occurred: " . mysql_error());
Now since the file works on other servers i am guessing it is something to do with the server it is on and might need something changed. I don't personally have root access to the server (just my part of the shared host). Is there anything I can do i php, editing the php.ini file or something I should pass on to someone with root access?
Edit: Ok it turns out that the server doesn't have access to outside databases, so thats why the IP didn't work. Thanks for all your answers but we have decided simply to change hosting provider. We need to be able to access an outside database.
This is on a hosting service? Check their documentation, there will be something that tells you where to find mysql. It isn't necessarily localhost.
For example, on startlogic.com, you use: yourdomain.startlogicmysql.com
Can you connect using mysqladmin using the same host, username and password?
mysqladmin -h $db_url -u $db_user -p $db_pass
Replace $db_xxxx with real values.
If that works from the same host as your php script, then sudo to the apache User and try the same test. One of those must be failing.
EDIT: nevermind on sudo part, I noticed that you don't have root access.
Something else to try: Use '127.0.0.1' instead of 'localhost'. I have had issues before where mysql stupidly assumed it could silently change 'localhost:' to '/var/run/mysqld/mysqld.sock'.
Your wording is not very clear, I hope you are not thinking you can connect to the same mysql server from any old web server just because you know the IP address and port number. If the web host is at all competent, they have probably firewalled mysql so it is only accessible through their own web servers.

Categories