How do I connect to an Oracle database from PHP?
Connecting to Oracle from PHP using ODBC Driver for Oracle PHP is one of the most popular programming languages for website development. ODBC drivers are connectors that make PHP development database agnostic — your software written in PHP will function with any vendor's database management system.
On the Home page, click Create, then click Connection. In Create Connection dialog, click the connection type, for example, Oracle Database.
You can use the SQL Gateway from the ODBC Driver for Oracle to query Oracle data through a MySQL interface.
Forth link in google after searching for your exact questions brought up the following link: http://me2learn.wordpress.com/2008/10/18/connect-php-with-oracle-database/
<?php
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.34)(PORT = 1521)))(CONNECT_DATA=(SID=orcl)))" ;
if($c = OCILogon("system", "your database password", $db))
{
echo "Successfully connected to Oracle.\n";
OCILogoff($c);
}
else
{
$err = OCIError();
echo "Connection failed." . $err[text];
}
?>
I assumed you want to connect php with oracle databases. so, I give you two of file, this is represent a basic php-oracle for your reference. good luck!
form.php
<form name="form1" method="post" action="login.php">
<label> User Name
<input type="text" name="nis" id="nis">
</label>
<label> Password
<input type="password" name="password" id="password">
</label>
<label>
<input type="submit" name="submit" id="button" value="Login">
</label>
</form>
login.php
<?php
//create table users (userid varchar2(10), password varchar2(20), constraint pk_users primary key (userid));
//insert into users values('kharis', 'pass123');
$nis = isset($_POST['nis']) == true ? $_POST['nis'] : '';
$password= isset($_POST['password']) == true ? $_POST['password'] : '';
if(empty($nis) or empty($password)){
echo "UserID atau Password kosong";}
else
{
$db = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = patronus.ad-ins.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)" ;
$connect = oci_connect("HR", "hr", "XE");
$query = "SELECT * from users WHERE userid='".$nis."' and password='".$password."'";
$result = oci_parse($connect, $query);
oci_execute($result);
$tmpcount = oci_fetch($result);
if ($tmpcount==1) {
echo "Login Success";}
else
{
echo "Login Failed";
}
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With