php

Why is PHP PDO DSN a different format for MySQL versus PostgreSQL?

When I connect to a MySQL database using PDO, the way I need to connect is: $pdoConnection = new PDO("mysql:host=hostname;dbname=databasename",user,password); But, for PostgreSQL, the DSN is more standard (IMO): $pdoConnection = new PDO("pgsql:host=hostname;dbname=databasename;user=username;password=thepassword"); Is there any reason w...

Google Chrome and Streaming HTTP connections?

Google chrome doesn't behave the same as other browsers when encountering this nugget: <?php while (true) { echo "<script type='text/javascript'>\n"; echo "alert('hello');\n"; echo "</script>"; flush(); sleep(5); } ?> It seems that it's waiting for the connection to terminate before doing anything. Other than pol...

How do I link files in PHP?

I have two PHP files that I need to link. How can I link the files together using PHP? The effect I want is to have the user click a button, some information is proccessed on the page, and then the result is displayed in a different page, depending on the button the user clicked.Thanks ...

Can web server settings override .htaccess file ?

I have build a website. in that website there is section to download file using php script. our company has two ISP connections. one ISP allows to dowload file but other blocks it. i thought this is browser problem but after hit and try methods, i come to conclusion that this is ISP problem. Am i right. please help me out. ...

php executing an executable (that writes to the serial port) and freezes

I have a php script that is executing an executable that writes to a serial port. However, everytime it runs system("c:\Untitled1.exe") it just opens up a cmd window and freezes. Anybody know how to fix this? Or if there is an easier way to get PHP to write to the serial port directly? (I've already tried these two: http://blogs.vinutho...

Is there a better way to change a DOMElement->tagName property in php?

Hi all, I just ran into this building a Textbox control for my MVC framework, where just before finalizing the whole document I call PreRender on everything that inherits from ServerTag (which in turn inherits from DOMElement). The only way i have found to change a DOMElement derived object's tagName is to replace it with a new one wit...

What is the simplest way to format a timestamp from sql in php?

What is the simplest, fastest way to complete the PHP code below such that the output is in a user-friendly format (e.g."October 27, 2006")? $result = mysql_query("SELECT my_timestamp FROM some_table WHERE id=42", $DB_CONN); $row = mysql_fetch_array($result); $formatted_date = ???($row['my_timestamp']); echo $formatted_date; ...

Best Framework for PHP and creation of RESTful based web services

Hi All, I'm looking to create a RESTful or pseudo-Restful based web service on a PHP/MySql stack. I'm wondering what some of the frameworks you suggest I look at? I've been looking at Zend with Zend_Rest, but I'm curious to other things out there. Ideally, there's be some form of ActiveRecord based object mapping to the exposed web s...

Headache getting php and sql server 2005 to run together

Below is the code that i cannot get to work. I know i have established a connection to the database but this returns nothing. What am i doing wrong? $result = "SELECT * FROM images WHERE path = ?"; $params = array("blah"); $row = sqlsrv_query($conn, $result, $params); $finished = sqlsrv_fetch_array($row); if($finished) { echo "blach"...

Multiple Login pages Cake PHP

Hey all, I'm trying to get authentication working to my liking in a cake php app and running into a snag. I want to let the user login from either the home page or from a dedicated login page. I'm using the Auth component to manage login and right now the login itself works. I am submitting the form on the home page to /Users/Login a...

Getting the first item out of a For loop

I am writing my own Joomla component (MVC), its based heavily on the newsflash module, because I want to display the latest 5 content items in a sliding tabbed interface, all the hard work is done, but I am having real difficult getting content out of the for loop. Here is the code I have so far default.php <ul id="handles" class="tabs...

Help setting up php for Eclipse

I'm trying to set up Eclipse for php web development. What I would like to do is preview a php web page from within Eclipse, but I cannot figure out how to do this. Is there an integrated web server of some sort that allows this, or do I have to set up IIS/Apache to do it? If so, do I have to have my php files in the web servers path,...

What do you think of PHP's new namespace separator?

PHP 5.3 (alpha) has had namespace support for a while using '::' as a separator. But due to some problems with ambiguity with this separator, the PHP team has decided on '\'. From a recent story on Slashdot: PHP finally is finally getting support for namespaces. However, after a couple hours of conversation, the developers picke...

PHP4: Send XML over HTTPS/POST via cURL?

I wrote a class/function to send xml over https via PHP4/cURL, just wondering if this is the correct approach, or if there's a better one. Note that PHP5 is not an option at present. /** * Send XML via http(s) post * * curl --header "Content-Type: text/xml" --data "<?xml version="1.0"?>...." http://www.foo.com/ * */ function sendX...

Problem with updating a MySQL field with PHP

I have a query: UPDATE choices SET votes = votes + 1 WHERE choice_id = '$user_choice' But when I execute it in my script, the votes field is updated twice, so the votes will go from 4 to 6 instead to 5. It doesn't seem that it is getting called twice because I echo out stuff to test this and only get one echo. Is there a way to have it...

CakePHP and Flex - Can they integrate and if so is it ugly or nice?

I'm looking at a new project and we are wanting to use Flex (to provide the easy integration with AIR and provide a desktop app for our project). How easy does CakePHP play with Flex or is there a better PHP framework to use with Flex, or should we use none? ...

regular expressions - match all anchors with optional attributes

Hi Guys I have a wysiwyg editor in my back end, and it is tripping up the first regular expression I wrote. This is in PHP4, using preg_replace(). I'm capturing the URI and linked text. @<a\shref=\"http[s]?://([^\"]*)\"[]>(.*)<\/a>@siU The client wanted all external links to open in a new window, so that's the expression I was using ...

PHP not running properly

I have been having some problems trying to get my PHP running. When I try and run any scripts they appear in the source and do not run properly. This is the htaccess file: # Use PHP5 as default AddHandler application/x-httpd-php5 .php AddType x-mapp-php5 .php AddHandler x-mapp-php5 .php Could this be the error? ...

How to set up OCI to connect to Oracle from PHP?

On the latest Ubuntu, I have a functioning PHP 5.2.4 installation. I want to use a remote Oracle server from PHP using OCI. I've downloaded the "Instant Client Package - Basic Lite" from http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html. I've unzipped the package containing the OCI libraries to a di...

Fastest way to convert string to integer in PHP

Using PHP, what's the fastest way to convert a string like this: "123" to an integer? Why is that particular method the fastest? What happens if it gets unexpected input, such as "hello" or an array? ...