PHP5/Call dll files in PHP
Expert: David Lefkon - 5/11/2007
QuestionQUESTION: 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
AnswerCOM 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