php5

Setting Up Multiple Classes to Represent Real-World Objects

PHP: If I have a customer class, and the customer can have a car and an invoice, and I want to have separate car and invoice classes, what is the most efficient way of setting them up? So, I have three different classes: customer.class.php customer_car.class.php customer_invoice.class.php What's the best way to set up the relation...

Any simpler / better way of making a mysql singlton db class in php?

Here's the one I'm using: <?php final class Database { private static $oDb; public static function init() { if(self::$oDb == NULL) { self::$oDb = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error()); mysql_select_db('mysql_db_name', self::$oDb) or die (mysql_err...

Update a row if ID exists else Insert.

This is the code of a .php file. The column "memberid" has a unique index. When a user enters a record with an existing memberid, the record must get updated else a new row is created. I also want to show an alert box. For test purposes I added like the way below, but it is not firing. No message is displayed. I also want to know wheth...

How to get public properties of a class?

I can't use simply get_class_vars() because I need it to work with PHP version earlier than 5.0.3 (see http://pl.php.net/get_class_vars Changelog) Alternatively: How can I check if property is public? ...

Is the method Doctrine_Table::find() deprecated?

Hi, I had a problem with the method Doctrine_Table::find(), since it's thorowing an exception of SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens I solved the problem by using Doctrine::getTable('City')->findOneById($id); instead and it works fine. When I tried to invistigate about t...

How can my web app retrieve Twitter user photos without hitting the API limit?

I am writing a web app that needs Twitter user's profile photos only. I retrieve these by parsing the users/show XML unauthenticated API call (http://apiwiki.twitter.com/Twitter-REST-API-Method:-users%C2%A0show): $twitterXML = simplexml_load_file("http://twitter.com/users/show/".$twitterUsername.".xml"); In my testing I have been hitt...

How to show nine images in a table , three images in each row using php

Hello, I want to show nine images in a table , three images in each row using php. ...

filesize function is crashing the Apache server

Hi all, On using filesize is PHP is crashing the apache server. No error is seen in the log file but window event viewer shows Faulting application Apache.exe, version 2.0.63.200, faulting module php_iisfunc.dll, version 5.2.7.7, fault address 0x00001085. regards Hemant ...

how can we retrieve file of remote system using php code

if we have tree structure of a file that located at the remote system then how can we retrieve that file Any code for that? ...

Dependency Injection simple implementation

Hi, after reading this question i wonder if someone can help me understand how to implement correctly Dependency Injection with these PHP Classes: class DBClass { private $mMysqli; function __construct(mysqli $database) { $this->mMysqli=$database; } function __destruct() { $this->mMysqli->close(...

On-The-Fly Image Generation in PHP

I'm developing a script that will allow people to generate a banner for them to use. It's customizable. During the customization process, I'd like to be able to have the banner reload on the spot. So they could see the changes. Once they create the banner and are completely done with it I would give them a link for them to use. This link...

Saving a .php file and saving the includes too (possibly)

The setup: I have a standard .php file (index.php) that contains two includes, one for header (header.php) and one for footer (footer.php). The index.php file looks like this: index.php <?php include header.php; ?> <h2>Hello</h2> <p class="editable">Lorem ipsum dolar doo dah day</p> <?php include footer.php; ?> header.php like thi...

Split records into two columns

I have a "student" table, having around 5,000 records, in my DB. I want to display those records in two divs. How do I do that without executing the query twice; only using a single query? ...

Handle quotes and commands in SQL string

In my MySQL table, I have a column of TEXT type. On my HTML Form, user pastes text into it that might contain "" , ' ( ) and so on. I want to know how to safely execute Insert Query if these characters exist in the text and might crash the query execution. How to handle them properly in PHP? ...

Why PHP is not showing exception?

I am using following code. When the query crashes, it is not displaying the ALERT that I defined in the "catch" block. <?php error_reporting(E_ALL ^ E_NOTICE); require_once("../Lib/dbaccess.php"); //Retrieve values from Input Form $CategoryName = $_POST["inCategory"]; $TotalMembers = $_POST["inTotalMembers"]; $D...

how to merge cells in excel using php ?

hello all, using php i exported report in excel.But got stuck in merging cells. i want to merge the first 10 cells to dispaly the Name of the Company. The variable which has the company name is in one cell, tried to merge the cells but i cudn't... can any one help me, thank u in advance. ...

DropDown must retain the text after POST

I want the DropDown text to be retained when the Form returns from POST. How to maintain the state? ...

How do I call a php function from javascript onclick() event?

For example, I have a php function: function DeleteItem($item_id) { db_query("DELETE FROM {items} WHERE id=$item_id"); } Then, I have something like the following: <html> <head> <script type="text/javascript"> function DeleteItem($item_id) { alert("You have deleted item #"+$item_id); } </script> </head> <body> <form> Item ...

PHP dump variable as PHP code

I'm looking for a function to dump a multi-dimension array so that the output is valid php code. Suppose I have the following array: $person = array(); $person['first'] = 'Joe'; $person['last'] = 'Smith'; $person['siblings'] = array('Jane' => 'sister', 'Dan' => 'brother', 'Paul' => 'brother'); Now I want to dump the $person variable ...

PHP setting input values with isset

Hi, I was wondering if there is a shorter way of writing the following code: <input type="text" name="username" value="<?if(isset($_POST['username'])){ echo $_POST['username']; }?>" /> I hate having to do this will all my forms as the isset() check really messes up my HTML and scares away the frontenders. ...