So I need to do something for work which is to simply take a users name/last name/email and store it to a database.
As a simple test, I put this in my connect file
php:
$server="localhost";
$uname="root";
$pass="PASSHERE";
$db = "DBNAMEHERE";
$c2d = mysqli_connect($server, $uname, $pass, $db) or die("Failed to connect to database yo" . mysqli_error($c2d));
if($c2d){
echo "connection made";
}else{
echo "connection NOT made";
}
This above works when I run it from WAMP locally or from my test live server on Godaddy etc. Now, the issue is that the production environment is an IIS box to which I installed Apache on it via the IIS tool. It's my first time working with IIS so....Just trying to figure things out But need a bit of assistance
For some reason, when I drag and drop the working file from my local machine to the production one for testing, the connection can never be made. It's always erroring out.
I've done a bit of digging around but to no avail. I've tried different connection strings, ive tried messing with the PHP.ini file on the IIS box, ive tried other simple examples but again it always fails. After doing some research and reading random posts here on SO, I came across another post that essentially said to make sure that "mysqli" extension was enabled in php.ini and it is.
Lastly, since i dont have a lot of time to get this working, I figured instead of saving to a database, id write locally to a file(csv and/or text file), with something like:
$putContentsIntoCSV = fopen("001registrations.csv", "a");
$putContentsIntoTXT = file_put_contents("001regtext.txt", $insertDataToText, FILE_APPEND);
if($putContentsIntoCSV && $putContentsIntoTXT ){
http_response_code(200);
setcookie("success", true);
echo "Your data has been saved!";
fputcsv($putContentsIntoCSV, $insertData);
fclose($putContentsIntoCSV);
}else{
http_response_code(400);
echo "no connection";
}
and that too works in my local env. and my Godaddy server, but as soon as i drop it inside IIS/apache, it doesnt work. To be clear, PHP works, but the functionality im needing doesnt.
Im pretty much stuck not sure what else to try. Any help is greatly appreciated.
Related
I've been trying to connect to my database, which has been created with PostgreSQL. However, it's unsuccessful.
I've watched lots of videos and researched quite a bit on here, but my issue seems too simple to be an issue for others.
The setup:
I'm hosting a local MAMP (free version) server, in order to use PHP.
I've downloaded and created a database using PostgreSQL locally, and am doing it from pgAdmin 4.
The code is written in a .php file, surrounded by PHP clamps, and the first print line is visible, so I believe there is a connection to the web page in my chrome browser.
I don't get any response from my if-else statement or the pg_query. All the page shows is: This is it:
Issue in short: What is the cause of me not being able to connect to the database and get data from it?
print "This is it:";
$db_connection = pg_connect("host=localhost dbname=first_creation user=postgres password=1234");
if($db_connection)
{
echo "connected";
}
else {
echo "not working";
}
$result = pg_query($db_connection, "SELECT text_content FROM strings");
you need to instll and configure the driver of pgsql in php.ini, please check the following question: How do I enable php to work with postgresql?
I have to connect to a FTPES server to retrieve data. Connecting and logging in works just fine, but my call with ftp_rawlist always fails and returns "false".
I am using this code for debugging purposes:
$ftp = ftp_ssl_connect($ftp_host);
if (ftp_login($ftp, $ftp_user, $ftp_pass)) {
$p = ftp_pasv($ftp, true);
var_dump($p);
$r = ftp_rawlist($ftp, '/', true);
var_dump($r);
} else {
echo 'Could not login';
}
$p is always true, $r always false.
When I connect to the server through Filezilla everything works fine and I can list directory content and more.
Update #1: Tried to not only list '/' but various subfolders on the server, they all fail through the script.
Update #2: Also tried to use ftp_raw with the commands to get a list, but the LIST command runs for some time and then does not return any result at all. But HELP lists LIST as a valid command for the server... Strange...
Update #3: I tried phpseclib now, but while I can connect, I can't login with the user/password combination. Support from the maintainer of the FTPES server is not happening ("works fine for $somebody else..."), so I need to figure this out another way... :-)
To come to an end with this: As the deadline for this project came closer a solution had to be found. And although this is no real answer in the sense of a question, I'd like to show what I have done to have this fixed. Maybe someone stumbles upon this through googling.
Next to the things mentioned in the OP, I also tried connecting to FTPS using PHP and certificate as auth which didn't work either. As nothing works as it is supposed to, I wonder if the FTPS server is really configured correctly after all.
The people who run the server told me that everything is fine and their CLI CURL-call works fine for them, so they have no need to further investigate issues.
As a result of this I set up a sandbox account on a server which has shell_exec() enabled. There is now a script running which gets a file listing via CURL and then downloads the files via CURL with the commands provided by the server provider. That server can be accessed through normal SFTP and therefore acts as a "Proxy FTP" which regularly mirrors the remote FTPS server file structure.
Although I find this "solution" quite "hacky" it seems to run robust, stable and fast for the moment. We will therefore be able to have the operation running this way in this year (it only runs around three months before christmas) and will have a look into it in the new year and develop a more stable solution.
Maybe the server guys are also less stressed then and willing to help... ;-)
Add the following call to ftp_set_option() in a line before the call to ftp_pasv
ftp_set_option($ftp, FTP_USEPASVADDRESS, false);
ftp_pasv($ftp, true);
I've inherited an issue on a Joomla site running on PHP 5.5 on IIS 7.5. Currently it accesses a SQL server through our firewall as part of a query, but this server may not always be available so I wanted to make sure the script dealt with this gracefully. We connect with
$itemodbc = "Driver={SQL Server Native Client 10.0};Server=$itemserver;Database=$itemdatabase;";
$con = odbc_connect($itemodbc,$itemuser,$itempassword) or die('SQL connection error');
but if I simulate the server being unavailable by changing the server's IP address this takes ages and eventually the page script (I believe) times out and errors. What I want to do is set this timeout to 5 or 10 seconds, and if this times out then I can continue the script only using the server's local database content, but I can't find where to set this up. I've found the mssql.connect_timeout entry in the php.ini but this doesn't make any difference (I'm sure this is for mssql_connect calls, rather than odbc_connect, so this makes sense), and there doesn't seem to be an ODBC equivalent, I've also tried appending "Timeout=10;" to the ODBC connection string, but this also doesn't seem to work. Hunting round google I have found what seem to be the settings for a Linux system, but obvisously that also isn't helpful. Where do I need to set this in Windows, or do I need to convert it to another database connection type?
I imagine you have this solved already, but I would have used some kind of PHP based code to 'test' if the server was online. A quick google showed this might be a possible solution for your problem (just change google.com to the direct route to your server, maybe an IP on a different port, or maybe something like server.companyhost.com)
function availableUrl($host, $port=80, $timeout=10) {
$fp = fSockOpen($host, $port, $errno, $errstr, $timeout);
return $fp!=false;
}
//Return "true" if the url is available, false if not.
if (!availableUrl("www.google.com")) {
print " some message that the server is down with neat html that suits your needs ";
exit;
}else{
//the connection is ok... proceed
}
I have to tell you guys first that I'm a newbie of web development but I just got an assignment to maintain website. I copy all important files on server and set my computer to be a localhost with MAMP. After I try to run page index.php on browser but it show me a result like "NO Connect Server". I dont get it why it show me like that. I has tested my localhost by create test.php to do something for testing like echo and it works fine.
Does anyone know how can I fix this problem?
Thanks,
regards
From what it looks like, there is no real way to tell what the real problem is. The only things I can think of are the usual ones: the MySQL server isn't actually running, the user name or password is wrong, or the user name isn't actually registered in the system. Sorry that I can't give more details, but you could find more information if you replace the NO connect Server with mysql_error() like this:
$db = mysql_connect('localhost','username','passwort') or die(mysql_error());
That will print out the error text when the script dies. With that information, you can start to decode what is actually going on.
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