I’m very happy PHP exists. It’s a bright shiny object to keep the stupid people away from more advanced things like Perl. : Randal Schwartz
Category Archives: PHP
Error: No input file specified
Today I was trying to configure Lighty webserver with PHP CGI.
After configuring I did “phpinfo()”. But it gave me this error:
No input file specified
After googling around for some time. I found the solution:
Open lighttpd.conf search for server.document-root. The value may be “/var/www” on Linux or “c:\lighttpd\htdocs” on Windows.
Now edit php.ini search for doc_root and set doc_root value equal to the value of server.document_root of lighttpd.conf.
Suppose you are on Linux then value should be:
doc_root = "/var/www"
And on Windows system doc_root should be c:\lighttpd\htdocs
PATENTED: Passing arrays to stored procedures
Today I was searching for a ways to pass arrays to stored procedures in MySQL and came across this interesting link:
http://www.freepatentsonline.com/5978580.html
Kartik was online and he gave me this link which gives better explanation with PDF’s:
http://www.google.com/patents?id=boAYAAAAEBAJ&dq=5978580
So its clear that I wont be able to do that with PHP-MySQL as its not and may never be implemented because of the patent.
Has any body managed to simulate this functionality in MySQL?
Uploading files with PHP
During my recent project I learned about uploading files using. For uploading files with PHP first step is to create a HTML form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<BODY>
<FORM METHOD='POST' ACTION='upload.php' ENCTYPE='multipart/form-data'>
<INPUT NAME="image" TYPE="file" />
<INPUT TYPE='Submit' VALUE='Upload' />
</FORM>
</BODY>
</HTML>
For form the attribute ENCTYPE='multipart/form-data' is very important.
Next step is to create a PHP script upload.php which will upload the file:
<?php
// Path where the file will be uploaded
$target_path = "/var/www/";
$file = $_FILES['image'];
$temp = $file['tmp_name'];
if(is_uploaded_file($temp))
{
if(move_uploaded_file($temp, $target_path.$file['name']))
{
echo "Upload successfull.";
echo "File type is: ".$file['type'];
echo "File size is: ".$file['size']/1024. " kb";
}
else
{
echo "File cannot be moved to $target_path";
}
}
else
{
echo "Unable to upload!";
}
?>
The target path given is an absolute path. I tried to give relative path but it didnt work. If you are using windows you can give path like “c:\\some_directory\\”.
Connecting MSSQL Server with Zend Framework on Linux
Few days ago we completed a project which used Zend framework and the database was MS Sql Server 2005. We had tough time deploying the project on Linux. Initially we started with Ubuntu but in Ubuntu php-mssql package is missing. We tried to compile it but didnt work. Then we decided to use Fedora which has php-mssql package. So the following steps should work for any distro with php-mssql package in it.
With PHP already installed we started with installing following packages:
- php-mssql
- php-pear
- freetds
Now we need pear mbd2 driver for mssql. You can install it using following steps:
First install mdb2 driver:
$ pear install mdb2
Now install mdb2 fro mssql:
$ pear install mdb2_driver_mssql
Zend framework uses PHP Data Objects (PDO) for connecting to databases. Though there is a way to connect to databases without PDO. On Linux we will use pdo_dblib driver for connecting to MS Sql Server. You can download pdo_dblib package from http://pecl.php.net/package/PDO_DBLIB (We have used version 1.0).
After downloading now we need to compile the package:
Untar the package:
$ tar zxvf pdo_dblib.tgz
Now we use pecl command which will build the package and generate the configure script:
$ pecl build package.xml
Change to directory and run configure and make:
$ ./configure $ make
Copy pdo_dblib to php’s modules directory :
$ cp modules/pdo_dblib.so /usr/lib/php/modules $ vi /etc/php.d/pdo_dblib.ini
Write the following line in the file:
extension=pdo_dblib.so
Next step is to configure freetds to connect MS Sql Server:
$ vi /etc/freetds.conf
And write these lines in the file:
[SERVER_NAME] host = <IP Address> port = <Port Number> tds version = 8.0
Finally set the pdo_type you specified in you project to dblib. We used a separate config.ini file, you can also do that in bootstrap.php:
pdoType = dblib
The project is deployed finally
I hope I havent missed a step. All’s well that end’s well