7 Replies Latest reply on Apr 14, 2010 12:54 PM by jgreco79

    PHP Service Sample Code

    jgreco79

      Flash Builder 4 gives you the option to create sample PHP code, but only gives an option for a MySQL database.  Does anyone have some PHP sample code for using Oracle?  My code I am using is working, but I am not getting the performance I was expecting.  The only difference I see in the sample MySQL code is that they are using a mysqli_stmt_bind_param and mysqli_stmt_bind_result statements, which I am not sure exactly how to do with the OCI8 extension in PHP.  Any help would be appreciated.

        • 2. Re: PHP Service Sample Code
          jgreco79 Level 1

          I've seen that function, but I am fairly new to PHP and am not sure how to use it.  It doesn't look as simple as the mysql binding functions.  Do you have any samples of how to use it?  I wasn't too clear on the samples in the PHP manual.

          Thanks,

          • 3. Re: PHP Service Sample Code
            jgreco79 Level 1

            Below is the sample MySQL code that I am looking at, how would I rewrite the bolded lines for the OCI8 extension?

             

            public function getAllItems() {
                    // TODO Auto-generated method stub
                    // Retrieve a array of records from the database and return that

             

                    // Sample code
                    /*
                    $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");       
                    $this->throwExceptionOnError();
                   
                    mysqli_stmt_execute($stmt);
                    $this->throwExceptionOnError();
                   
                    $rows = array();
                   
                    //
                    // e.g. if the table has columns ID, NAME then mysqli_stmt_bind_result
                    // would look like this => mysqli_stmt_bind_result($stmt, $row->ID, $row->NAME);
                    //
                    mysqli_stmt_bind_result($stmt, <ENTER VALUES BASED ON ABOVE COMMENT>);
                   
                    while (mysqli_stmt_fetch($stmt)) {
                      $rows[] = $row;
                      $row = new stdClass();
                      mysqli_stmt_bind_result($stmt, <ENTER VALUES AS ON LINE 79>);
                    }
                   
                    mysqli_stmt_free_result($stmt);
                    mysqli_close($this->connection);
               
                    return $rows;
                    */    
                }

            • 4. Re: PHP Service Sample Code
              SpaghettiCoder Level 3

              Sorry, don't know.

               

              I've never used oracle, can't afford it.

               

              Php and Mysql, even then not the newer mysqli extension, still sticking with the older extension.

               

              You're probably better off asking in a php/oracle forum.

              • 5. Re: PHP Service Sample Code
                jgreco79 Level 1

                Thanks for the help.  The whole thing I am trying to figure out is the Zend AMF.  From what I have read is that it should be much faster than using XML.  But it actually seems like everything is getting returned about the same or slower.  So I was thinking that since I did not bind the results that could be the reason.  Here is the code I have been using.  I'll check the Oracle forum too (it isn't the greatest).

                 

                 

                public function getPlaces(){

                $connect = oci_connect(DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_SERVER);

                 

                 

                $query = "SELECT * TABLE";

                 

                 

                $stid = oci_parse($connect, $query);

                oci_execute($stid);

                $ret = array();

                 

                while ($row = oci_fetch_object($stid)){

                $ret[] = $row;

                }

                oci_free_statement($stid);

                return $ret;

                }

                • 6. Re: PHP Service Sample Code
                  SpaghettiCoder Level 3

                  Are you retreiving like thousands of records?

                   

                  Is it slow only on the first query? or is it slow on the first and every query.

                  • 7. Re: PHP Service Sample Code
                    jgreco79 Level 1

                    1.78s for the initial query (about 550 results)

                    1.58s if I run the query again

                     

                    Its not slow, but its slower than I was expecting.


                    I think my PHP code is fine after watching a few of Flash Builder 4 data videos.