WAMP server stalling when trying to run mysql test file - php

I have just installed WAMP server, using Port 81, on a Windows 64 bit machine. It runs and I can open the index.php file with it. However, when I try to open the testmysql.php file, it appears to kill the server.
After trying to run testmysql.php, which never loads, I get the same problem with the index.php file - it will not load either. I can then get the index.php file to load only by restarting all services on WAMP server.
I have Avira running on the computer, but it doesn't seem to be causing a problem. With it running, I can load and refresh index.php as many times as I want. It appears that the problem is always created by trying to run the testmysql.php file.
The code for the testmysql.php file is as follows:
<?php
$link = mysql_connect('localhost:81','root','');
if (!$link) {
die('Could not connect to MySQL: ' . mysql_error());
}
echo 'Connection OK'; mysql_close($link);
?>
Any thoughts on why this is happening? Thanks for your help.

Related

Connecting to a MS Access database from PHP on Linux

My client has been running a Windows server for years but we are now moving to a separate Linux machine for the web app I have created for them. Currently we run PHP on the Windows server on which we are able to connect to an MDB file that is on the same disk. This is a file from an external party, the web app uses MySQL. In the new setup we have a Linux web server (Apache/MySQL/PHP) and a Windows 2016 server which are connected via VPN and we have mounted a share on the Windows server in which the MDB file is located. So far, so good, however I can't seem to query the MDB file. The connection is made, not error there, but every query I run returns an error or nothing not sure. This is my code:
<?php
$db=new PDO("odbc:Driver=MDBTools; DBQ=/mnt/<dir>/<file>.mdb;");
$query=$db->query("SELECT * FROM <table>;");
$return=array();
if($query) {
while($result=$query->fetch(PDO::FETCH_ASSOC)) {
$return[]=$result;
}
}else $return['error']=1;
//close
$query=null;
$db=null;
print_r($return);
?>
Currently everything returns error > 1.
PDO throws the following error:
Connection failed: SQLSTATE[08001]: Client unable to establish connection: 1 Couldn't parse SQL (SQLExecute[1] at /build/php7.2-pRoOsC/php7.2-7.2.24/ext/pdo_odbc/odbc_stmt.c:260)
I found the solution to my problem was removing the ; from the query.

phpwebsocket not working

This is the tutorial I used:
http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/comment-page-1/#comments
Basically I downloaded the source code, placed the files in a folder: http://mmhudson.com/ws
server.php:
http://mmhudson.com/ws/server.php
I simply can't get it to connect. I tried running server.php from both the command line and the browser and both times it wouldn't connect. The ws folder has all the files in the downloadable source included.
Any ideas of what I can try?
I think I found the solution. You are opening a connection to localhost/127.0.0.1. As soon as you put the code on a server, you'll have to specify the server URL instead of localhost/127.0.0.1 for the client. I tested the server.php and it is working fine, only the client doesn't connect to it.
Try this for index.html
Server = new FancyWebSocket('ws://mmhudson.com:9300');

PHP / FTP - Simple ftp_get won't work on local server but does in production - Troubleshooting

I'm having a little problem with ftp_get. The script won't work when running on our local development server running on Centos 6.
I've done some research on Stack Overflow and tried most of the solutions without getting it to work.
I have tested the same script on a production server running Centos 5.x + cPanel and it's working.
I am wondering what could cause this on the local server?
Is there any specific settings for the file transfer to work?
Here's the list of things I've tried so far:
Errors, error_reporting(E_ALL) and see if there's any error. They were none.
Passive connection, ftp_pasv($connection, true) but it doesn't change anything.
Transfer modes, tried FTP_BINARY and FTP_ASCII. Nothing changes.
Tried using a file handler to save on the local server, didn't work either.
The original script runs in batch (download all files in a folder with specified filename). When running that script, I can say 3/4 of files get transfered succesfully to the 'dev' server.
Say about only 1/4 of them get the 'failed'. So the following script was used to troubleshoot / test-download some files that failed during the batch transfer.
They also failed transferring using this script.
I've checked all the permissions (chmod) on the distant server. Everything is set to 666.
Here's the code I'm using. It's very similar to the example on php.net
// Connection to ftp
$connection = ftp_connect($hostname);
// Login to the FTP
$login = ftp_login($connection, $username, $password);
// Passive might help?
ftp_pasv($connection, true);
// Test login
if ((!$connection) || (!$login)) {
echo "FTP Connection failed<br /><br />";
exit;
} else {
echo "Connection success<br /><br />";
}
$local_file = 'file.zip';
$server_file = 'file.zip';
// Download and save file
if (ftp_get($connection, $local_file, $server_file, FTP_ASCII)){
echo "Download win <br />";
} else {
echo "Download failed <br />";
}
Thanks for your time,
first try checking the same thing from command-line/shell of your local centos machine. Use "ftp " command and see if it works there. Mostly, it seems like a firewall problem to me.

php can't see local mysql server

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.

Connecting to MySQL with PHP

I have MySQL running such that I can open a client command line and log on and make databases, tables, etc.
I wanted to do some AJAX. Doing AJAX with ASP, SQL Server, etc is not advisable since both places where I am hosting my websites do not use the Microsoft products. So I am forced to do my development with PHP and MySQL.
I just about have everything set up. I have set up IIS so that I can go to my localhost and I can test out web pages. I have PHP installed so that I can pull up the PHP setting pages.
The problem occurs when I try to bring up the MySQL database in PHP. I use this very simple PHP command:
<?php
$con = mysql_connect('localhost', 'testuser', 'testpassword');
?>
When I try to connect to the mysql database through PHP, I get this error:
Click here
I figure the problem must be in the settings that are in the php.ini. But it seems that my php.ini is set up for MySQL although it is not mentioned in the output when I query the phpinfo page with this code
Here is the result from this:
Click here
It looks that your php is missing mysql module
in php.ini make sure that you have correct extensions path eg.:
extension_dir = "C:\php\ext"
and make sure you have commented out:
extension=php_mysql.dll
extension=php_mysqli.dll
Which version of PHP are you running and are you sure you have MySQL installed and running on localhost with a username of "testuser" and a password of "testpassword" (and have you reloaded the privilege tables after creating those users)?
Have you got IIS configured to log errors into a file - does that provide any more information?
Create a new PHP file that contains the following:
<?php
phpinfo();
?>
This will helpy you to discover if MySQL has been compiled in properly etc. Can you access the MySQL server from the command line; using something similar to:
mysql -u testuser -ptestpassword testdatabase
If you get a prompt from MySQL, the service is running and we can better help from there.
Hope that helps a little!
Are you selecting the database? After your connect statement, you need to use:
mysql_select_db($databaseName, $conn);
Documentation here: http://php.net/mysql_select_db
What I would do is to download the complete package in one go (Server, MySQL and PHP). There are tons of good resources like WAMP or MAMP (for MAC users). Once you download the package the installation is just easy and you don't have to set anything as it does it automatically.
They also have phpMyAdmin where you can manage your database and its users and privileges.
Once you got your server running you can test that code that seems fine for me. Try running something like this:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected';
mysql_close($link);
?>
Cheers

Categories