PHP - How to get data from database which is in another pc? - php

A quick question. I have two laptops, installed with WAMP, both using MYSQL.
I tried ping each other -> success
Configure the phpmyadmin -> require and allow ip addresses ->success
View phpmyadmin of another pc typing 192.168.0.*->succes
But when i tried to putting php code on laptop A with '192.168.0.*' as host , it came out an error, saying server not responding, run time error...

Try giving the following line in the mysql configuration file. And make sure the privilege is there for the user.
bind-address=YOUR-SERVER-IP

Related

Where is /usr/local/lib on online server

I have a server hosted on 000webhost.com
In the file manager there is a public_html folder where I store my website files, but no \usr folder.
Generally I could just access this file through the command line or terminal but this is not the case on this server. Unless there are command line tools that I simply couldnt find (I know it is a linux server);
I ran phpinfo() and the configuration file path was in usr/local/lib but I have no idea how to access that.
Any ideas? Thanks in advance.
Go to http://www.000webhost.com/faq.php look at the section on connecting to MySql. Your solution is likely there.
Here is a synopsis:
If you cannot connect to MySQL server, there could be some causes:
- Incorrect MySQL hostname.
Never use 'localhost' as your MySQL hostname! You can find your MySQL hostname by logging on to members area, entering control panel and clicking on MySQL icon.
- Incorrect MySQL username / password or database name.
You can find / setup MySQL username and database by clicking on MySQL icon from control panel. And you can change MySQL password by clicking on phpMyAdmin icon.
- Database failed to setup.
In a very rare cases MySQL database can fail to setup. To confirm this, please try to enter phpMyAdmin for any database. If you see database there, that means it setup was successful. And if you get access denied error by trying to enter phpMyAdmin, please delete the database and setup the same MySQL database again.
Please note that always you must give about 1 minute for any changes to apply on server.
If you still unable to connect to MySQL you check if it is server or your script problem in this way: if you can enter phpMyAdmin and see you database there, that means everything is working fine on our side. It's a problem with your PHP script.

phpMyAdmin unable to connect to MySQL Server

I have been using xampp 1.7.4 on a local installation php version is 5.3.5 for several years without any problems. I develop Joomla! websites offline and then upload to the server.
My phpMyAdmin stopped working, giving this error message:
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
I am a complete dummy with servers and NEVER fiddle with settings I do not fully understand.
Can anyone please advise?
Go inside your phpMyAdmin directory inside XAMPP installation folder. There will be a file called config.inc.php. Inside that file, find this line:
$cfg['Servers'][$i]['password'] = ''; you must make sure that this field has your mysql root password (the one that you set).

MySQL query runs okay on test machine, but fails on ISP server

I am testing with MySQL on my home machine using an Apache server under XAMPP with the MySQL settings: Server: localhost via TCP/IP, version 5.5.16.
I have a query: SELECT * FROM project WHERE refno = $refno;
This works perfectly on my test machine. When I try the same thing on my ISP server, which has the following settings: Server: localhost via UNIX socket, version 5.0.92
I get the message:
"supplied argument is not a valid MySQL result resource"
Is the problem the difference in the settings? Is there anything I can do to get it working?
I would recommend you first make absolutely sure you have a valid database connection. Look for mysql_connect in your script, and make sure it is being passed the proper parameters. Look for the code examples on the man page to see how to add die() calls to catch any problems. Using die() is not a practice I would recommend on production code, though. You would usually want to catch and log errors, instead of having the script die.
Once you have made sure your connection returns a ressource, if it still chokes on you make sure you are sending the proper parameter (database name) to mysql_select_db.
Once these forementioned two functions play nice, your query should execute no problem.
Hope that helps, good-luck.

Wordpress installation - php and mysql are not talking to each other to access database?

I'm trying to get a wordpress local install working on my Mac.
I've recently set up a database, username and password using the MySQL client as per the instructions in the wordpress codex. That part is ok.
When I go to the local site on my computer I'm prompted by wordpress to set up the wp-config.php file. Putting in the same details that definitely work with the MySQL client returns an error.
Manually updating these details in the 'wp-config-sample.php' file and renaming it as 'wp-config.php' also doesn't work - I'm now greeted with a big bold message: "Error establishing a database connection".
From what I can gather, php and mysql are not communicating with each other properly.
I've changed the apache 2 configuration file found in 'etc/apache2/httpd.conf' and uncommented the line which loads the php5 module: LoadModule php5_module libexec/apache2/libphp5.so
and restarted the apache server. This has still not fixed my problem. I'm stuck on what to do next... help appreciated please!
It's been fixed now.
php was looking in the wrong place for the mysql.sock file, and couldn't communicate with the mysql database, meaning wordpress couldn't be set up.
On the command line I typed
ps aux | grep mysql
to bring up as much info about mysql that I could. From this I saw that the mysql socket on my computer is being used at /tmp/mysql.sock
Meanwhile, in the "wp-config.php" file, I changed the line define('WP_DEBUG', false); to define('WP_DEBUG', true); and refreshed my web browser that was showing my localhost setup. This now said a lot more info than "Error establishing a database connection" - infact I could see that the mysql.sock was not configured correctly at all.
Creating a 'phpinfo.php' file with just the single line of code <?php phpinfo(); ?> was the pivotal turning point for me.
Putting that 'phpinfo.php' file in my localhost directory and then viewing it from my web browser not only definitely confirmed that the mysql.sock file was not configured properly, but it also showed where the configurations were being loaded from on my machine: '/private/etc/php.ini'
The next thing I did was open up the 'php.ini' file in a text editor and doing a quick find and replace to update the correct location of mysql.sock.
Finally, a restart of the local apache server needed to be done to fully update all the new settings that I'd been fiddling about with.
sudo apachectl restart
Now everything works fine!
The Error-Message "Error establishing a database connection" indicates clearly, that the php-script can not establish the connection. This can have one of the following reasons:
Your host in the wp-config.php is not correct.
The mysql-server does not listen on that host
The user you set up in the mysql has no privileges to connect the way you are trying
The firewall blocks the access of the php-script to your mysql-host
Try to connect the database with the same settings of your wordpress using Sequel Pro (or any other GUI to connect a mysql database). If the connection works, the problem 2. and 3. isn't your problem.
Look in your firewall-log to make sure 4. is also not your problem.
If all problems are excluded (even 1. after a final check), try to run something like phpMyAdmin to connect your database, to make sure your php-installation has the needed drivers.

Apache2, PHP5, and Interbase/Firebird on Windows 2003/XP

I have recently upgraded from Apache 1.26 and PHP 4.3 to 2.2.11 and 5.2.9 respectively. With my original setup I had a scheduled task set to run every Sunday for a weekly newsletter. It would connect to my database (Interbase/Firebird) to find out what events were opening for the following week and get the list of addresses the email will be sent to. Of course, I had to change how PHP the task was setup since command line execution has changed slightly from version 4 to 5. Once that was fixed the real problem reared it's head.
Now when executing any script from the command line I cannot connect to my database. I receive the following error from ibase_errmsg: Unable to complete network request to host "localhost". Failed to locate host machice. Undefined service gds_db/tcp.
The same script works perfectly from the browser. Also, the database connect code is used all through my site for logging in, getting records, and updating records.
If anyone has any idea why a script will not connect to the database when executed from the command line, please help.
Sorry for the post everyone. I have answered that question. I had to copy my fbclient.dll file in to my PHP folder and rename it gds32.dll.
Does anyone know why I had to do this for executing command line scripts only, and not for scripts that run in the browser?

Categories