php

New programmer work rate and expectations

Hi there. I'm a new graduate and yave just started working a few weeks past as a web programmer. I've kind of been thrown in at the deepend and have been put straight on a project that appears on the face of it to be relatively simple, but there a lot of little intricacies that are making it quite difficult. What sort of work rate will...

Trouble in PDO and sqlsrv land.

I set up a site on my local system using PDO and a MySQL Database. I used PDO because when the site goes on the live server I have to user SQL Server and I was hoping PDO would take care of all my query conflicts. Now that I'm up on the live server I get an error whenever the application uses the "LIMIT" function. I realize this is a My...

Singleton factory for managing and wrapping multiple database objects

I'm building a PHP application which has to interact with several structurally identical databases. I'd like to use a singleton factory to hand out connections to the databases and minimize the number of duplicate connections. I'd also like to wrap the database class with a few functions. It would be extremely convenient if I could do a...

What would cause & in URLS to automatically be converted to &?

Im a little stuck. I developed a script and for some reason it is converting & in URLs to & automatically. This is the line that is causing the issue: $accessToken = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=' . APPID . '&redirect_uri=' . APPURL . 'callback.php&client_secret=' . APISECRET . '&code='...

PHPUnit coverage now incomplete as class' opening brace is not covered.

Hey everyone, I've been using PHPUnit to to do unit testing on a Symfony/Doctrine project I'm working on. It was working fine until yesterday when various classes dropped from 100% coverage to 98-99%. The reason for the change is because the opening left brace of these classes is no longer considered "covered" for some reason. Here's a s...

Doctrine Record Listener

I have a listener which contains a preSave() method. Is there a way for me to halt doctrine from calling the save method if a condition fails. Unfortunately I am not allowed to throw an exception. Is there any other way? ...

PHP - I need to split a large string into an array, but the split point cannot break a tag

I wrote a script that sends chunks of text of to google to translate, but sometimes the text, which is html source code) will end up splitting in the middle of an html tag and google will return the code incorrectly. I already know how to split the string into an array, but is there a better way to do this while ensuring the output stri...

SQL query to get data from a large list of strings

I have a large list of strings (1500 email addresses to be more specific) and I need to look up a piece of data in a very large DB table for each of the strings (e.g. the primary key, mydataitem). How can I do it efficiently? For example, this is way too slow (amongst other problems): $stringArray = ('foo','bar','baz',..., 'for 1000s...

Flex vs. PHP: What are the pros and cons of each? Which language should I use?

Flex vs. PHP: What are the pros and cons of each? Which language should I use? ...

How to allow users to accept payment from other users?

I am working on an apartment CRM of sorts and I would like to allow renters to be able to pay bills online. My issue is that I don't know how you would implement a system that would work in this case. I would both need to accept payment from landlords/owners for providing a service to them and also allow them to collect rent from their r...

Cut an UTF8 text in PHP

Hi, I get UTF8 text from a database, and I want to show only the first $len characters (finishing in a word). I've tried several options but the function still doesn't work because of special characters (á, é, í, ó, etc). Thanks for the help! function text_limit($text, $len, $end='...') { mb_internal_encoding('UTF-8'); if( (mb_...

SELECT/UPDATE and SELECT/INSERT kills MySQL server

I run a server that is getting killed by the number of requests it is getting from one of our iPhone games for storing scores. By this I mean the server becomes unresponsive. I only really know enough MySQL/PHP to get by, so I am floundering in my attempts to fix this. I am sure its a problem that can be optimised because we have a dedi...

How do I open an image and re-save it using ImageMagick?

I'm doing it to image uploads to prevent any embedded malicious code. Am I right in doing this? But yeah my main question is how to actually do it, because I've never used ImageMagick before - I've just installed it on my server. ...

Magento Custom Left Navigation Template displaying twice

I created a custom template (mytheme/template/catalog/navigation/left_parent_category.phtml) to display the parent categories of the current category. <?php echo '<div class="box base-mini">'; echo '<ol>'; $currentCat = Mage::registry('current_category'); if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCa...

Php, MySql - Multiple DB connections and mysql_insert_id()

I have 2 database connections, and I want to get the last inserted ID from one of the connections. $old_database = mysql_connect('host', 'username', 'password'); mysql_select_db('database1', $old_database); $new_database = mysql_connect('host', 'username', 'password',true); mysql_select_db('database2', $new_database); $sql=mysql_query...

How to turn an image's file path into the actual image?

Hello, I've saved a user's respective picture in a folder named 'profileportraits'. So when a user uploads their picture, it is saved into that folder. Furthermore, I also save the 'portrait path', i.e. the location/name of the photo onto a MySQL database for user data. My question is: I am able to echo the Portrait Path, where the user...

How to obtain the returned cookie after a POST in PHP?

Hi, Let's say I have a website called (example.com) which will have a php file (example.com/call.php). call.php will have a post method that will post to the website exampleOne.com/login.php with the right parameters. exampleOne.com will return a header with a cookie that will confirm the authentication of the user, how do I obtain the ...

Rethrowing an Exception causing containing Catch to reexecute

Using PHP 5.3.2 I'm handling an Exception in a catch block. After logging the error, I want to pass it on for the Framework to handle. When I try to rethrow the exception, throw $e, the current catch block is reexecuted causing a duplicate entry in my log and then the exception is passed on up. ...

secure way to deliver password over URL?

hey guys, i wonder if there's a secure way to deliver a password with an URL (like ?p=mypassword) how can i encrypt and decrypt such a password so it's secure. i guess md5 is not working in my case because the password must still be readable. It's an FTP passwort which gets passes along to the ftp_connect. i think md5 doesn't work in t...

How would I preg_replace the following?

I've got this snippet of code that I will be replacing in various places and I was wondering how would I write the pattern to preg_replace it? Thanks! <div class="leftside item1"> <label for="item1">Item1</label> </div> I'd like to replace it with: <div class="leftside item1"> <label for="item1">Item1</label> </div> <di...