php

What does a successful MySQL DELETE return? How to check if DELETE was successful?

Using PHP, I am trying to delete a record, but I want to check if it was successful or not. Is anything returned from a successful DELETE FROM foo where bar = 'stuff'? Alternatively, do you know any other ways to check if a DELETE was successful? Or am I better off just making sure the row exists before I delete it? I am trying to avoi...

maintaining configuration differences between dev and live environments during deployment from SVN

We use the ExpressionEngine CMS (php) to create websites. For each site, we set up a subversion repository and commit the EE installation as well as any custom templates, images, javascript, etc. that are used. Included in the repository is the file containing all of the environment variables and the .htaccess file. We have a developmen...

Running a Cron Job

If I have a cron job that run every 10 minutes and for some reason this one time it takes 12 minutes to run the job, will cron start another instance of my code while the previous one is still running? if so how can you prevent this on linux? ...

PHP / Zend Mechanisms for Rewriting

Hey there, this is a newbie Zend question. Under a site location: “mydomain.org/subA/subB”, if we go to this location without logging in (or having a session), it i) redirects to a login page. Otherwise, it ii) redirects to a race registration form. Now, I’d thought that Apache rewrite rules did that, but there’s not config that indicate...

Getting Mime-Types Over FTP In PHP

I'm writing an object in PHP that displays files on an FTP server. I am using PHP's built in FTP functions to retrieve most of the details I need (filename, size, last modified, etc.). However, there are no functions to get the mime-type of a file on the server. I have tried two different methods that work, but I'm having some issues....

Why is php's fsockopen returning (Resource temporarily unavailable)?

I have a very simple server php code like this function listenForClients() { $this->serviceConnection = socket_create(AF_UNIX, SOCK_STREAM, 0); socket_bind($this->serviceConnection, "\tmp\mysock", 0); socket_listen($this->serviceConnection, 10000000); while($clientSocket = socket_accept($this->serviceConnection...

Conditional formatting of a float in PHP

I'm retrieving a float value from a mysql database on a php page (2.5, 3.0 etc) I would like to format this value so that if it is actually an integer, it should show zero decimal places. (it should output 3 instead of 3.0, but output 2.5 as 2.5) What would be the simplest way to achieve this? ...

Form _POST array problem

Hi guys. I have the following code: if ( (isset($_GET['slAction'])) && ($_GET['slAction'] == "manage_label") ) { $formData = getFormData(); foreach ($formData as $key => $value) echo "(Key: $key, Value: $value )<br /> "; } // All form fields are identified by '[id]_[name]', where 'id' is the // identifier of the form type...

selective iteration of array in php

Is there a way of iterating through an array but performing an operation on every other element? ie If I have an array with 13 elements how do I do something to only elements 2,4,6,8,10 and 12? ...

When calling a Python script from a PHP script, temporary file that is created on a console run, is not created via the PHP invocation.

Scenario: I have a php page in which I call a python script. Python script when run on the command line (Linux) shows output on the command line, as well as writes the output to a file. Python script when run through php, doesn't do either. Elaboration: I use a simple system command in PHP to run the python script as: /var/www/htm...

Pulling a group from a database

Alright i have a magic cards site and im trying to pull all of the cards from a certain set if you click on the set on the home page. www(dot)magiccards(dot)me the code on the first page is: <?php require("mysqlconnect.php"); $query = "SELECT COUNT(*) AS `Rows`, `set`,id FROM `magic_cards_copy` GROUP BY `set` ORDER BY `set`"; $r...

Problem with Global Variables

I'm somewhat new to OOP programming so it's very likely I'm making some stupid mistake. Here is my problem. When running my code I get the following error: Fatal error: Call to a member function checkLogin() on a non-object in /application/libraries/Session.php on line 30 Below is the Session.php file (I've commented line 30 to mak...

Coding standards: Large amount of arguments

Hey, I'm a fresh out of college graduate. I'm working on a project that I expect will be ultimately maintained by somebody else. I keep encountering an annoying situation on this project, and that is objects that require many private variables and as a result very long constructors. Apart from variable naming, there isn't any coding sta...

Get Start and End Days for a Given Week in PHP

I'm trying to get the week range using Sunday as the start date, and a reference date, say $date, but I just can't seem to figure it out. For example, if I had $date as 2009-05-01, I would get 2009-04-26 and 2009-05-02. 2009-05-10 would yield 2009-05-10 and 2009-05-16. My current code looks like this (I can't remember where I lifted it ...

Resolve Windows environment variables in PHP

I want to write to a file in the windows temp directory. I know that in the command line you can use the environment variable %TEMP% to get the right path, however trying to do something like this: file_put_contents("%TEMP%\\myfile.txt"); ...does not work because the environment variable isn't being resolved. Is there a way to do this...

How does Robotreplay work? Can it be coded in php/javascript?

Hi, I'm looking to find out how robotreplay works. (Basically, it shows a movie of a visitor's mouse, and where he clicks when he enters a site) I don't know much about ajax, and I'm learning, and I'm trying to figure out if I can replicate what they are doing in a basic way. Would stuff like onmousemove or onscroll be useful? BTW, thi...

mysql "with rollup" query morphed into a tree structure

Background: I have this "with rollup" query defined in MySQL: SELECT case TRIM(company) when 'apple' THEN 'AAPL' when 'microsoft' THEN 'MSFT' else '__xx__' END as company ,case TRIM(division) when 'hardware' THEN Trim(division) ...

How can I use a different object inside of a class?

If I create an object inside of the main scope: INDEX.PHP: $db = new database(); Then how can I use this same object inside of a completely different class? ANYTHING.PHP: class anything { function __construct(){ $db->execute($something); # I want to use the same object from INDEX.PHP } } Would I need to make $db a...

Why my search wont refine!?!?!

I have this bit of code: //Restrict the SQL query with an AND clause if a member has been selected if ($form_member_id != 0) { $query .= "AND photos.member_id = '$form_member_id' "; } It is meant to refine a search query down to only the selected user, so the whole query together reads: SELECT photos.photo_id, members.member_name, p...

Get the First or Last Friday in a Month

I'm trying to write a calendar function like this function get_date($month, $year, $week, $day, $direction) { .... } $week is a an integer (1, 2, 3...), $day is a day (Sun, Mon, ...) or number, whichever is easier. The direction is a little confusing, because it does a different calculation. For an example, let's call get_date(...