You are here:

PHP5/Call dll files in PHP

Advertisement


Question
QUESTION: Hi,

I have created a .dll file in Visual Basic which migrates data from oracle to mysql. I would like to know how to call and display the mysql database information in PHP.

Regards
Suba
ANSWER: Create a php file (display.php) that will

//connect to the database:

$db_host = 'localhost';
$db_user = 'root';
$db_user_pw = 'root';
$db_defdb = 'mydb';


// see http://us2.php.net/function.mysql-connect for more info
$conn = mysql_connect($db_host,$db_user,$db_user_pw) or die ("Could not connect");
mysql_select_db($db_defdb,$conn) or die ("Could not select DB");

// and then query these tables:
// data is field gotten from URL in format &data=2435 or from posted form

$query = "SELECT * FROM tbl_data WHERE fld_id = ".$_REQUEST['data'].";
$result = mysql_query($query);
if(!$result)die(mysql_error());

         
while ($row = mysql_fetch_array($result, MYSQL_NUM))          
{
 // the following alters the background color of each row
 $count += 1;          
 if ($count % 2==1)          
 {  
   echo"<tr bgcolor=\"#CAE1F7\">";          
 }          
 else          
 {
   echo "<tr bgcolor=\"#ffffff\">";          
 }
         
 echo"<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td></tr>";          
}

David Lefkon

---------- FOLLOW-UP ----------

QUESTION: Hi,

The above coding is displaying the database information in php but I want to call a .dll file in php.

Thanks

Answer
COM functions are only available for the Windows version of PHP.
.Net support requires PHP 5 and the .Net runtime.
No installation needed to use these functions; they are part of the PHP core.


First create your ActiveX dll (Visual Basic):
Name your project as "foo" and class as "bar".

'---start VB code---
Public Function hello() As String
   hello = "Hello World!"
End Function
'---end VB code---

Then make the dll and register it with regsvr32.exe

Now create your PHP script:

<?php
$obj = new COM("foo.bar");
$output=$obj->hello(); // Call the "hello()" method
// once we created the COM object this can be used like any other php classes.
echo $output; // Displays Hello World! (so this comes from the dll!)
?>


http://www.php.net/manual/en/ref.com.php
http://devzone.zend.com/node/view/id/762

PHP5

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Lefkon

Expertise

I can answer your questions about forms, validation, processing or any other general questions on LAMP (Linux, Apache, MySQL, PHP) Stack. I also have Javascript knowledge.

Experience

Working web programmer.

Education/Credentials
BS Computer Science.

Awards and Honors
Summa Cum Laude.

©2012 About.com, a part of The New York Times Company. All rights reserved.