Oracle MySql Sqlite Connect **Only Zend comes with Oracle Oci8 extension

hamburgerfensuckedΑσφάλεια

20 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

107 εμφανίσεις

Oracle

MySql

Sqlite

Connect

**Only Zend comes with Oracle

Oci8 extension

Connect

Connect

$conn = oci_connect('userna
me',
'userpassword',
'
Instancename.
connectiionpath

);


$dbh = new
PDO('mysql:host=
xxxx;dbname=xxxx
,'user
','
password

);

$db = new
PDO("sqlite:
filename
.db");

Catch execpton

Catch exeption

Catch Exception

if (!$conn) {


$e = oci_error();


trigger_error(htmlentities($e['message'],
ENT_QUOTES), E_USER_ERROR);


}


catch (PDOException $e) {


print "Error!: " . $e
-
>
getMessage() . "<br/>";


die();

}

catch(PDOException $e)


{


print 'Exception : '.$e
-
>getMessage();


}


close

close

close

oci_close($conn);

$dbh = null;

$db = NULL;

Reads don’t block reads and write
s don’t
block reads. D
eadlocks are
rare.

Almost unlimited possibilities with
PL/SQL programming.

High level of security is inherently built
into Oracle.

Expensive: Requires an Oracle DBA
or a
DBA service provider to remotely
maintain your database. A cloud
instance provider like Amazo
n is an
inexpensive option for development and
startups.

Originally open source but after Oracle

acquired Sun MySql users need to buy a license for
commercial use but less expensive than Oracle..

Free edition is downloadable with no warranty.


Acce
ss to tables in root can be a

security risk
.



A very compact flat file
database with surprising
capabiliti
es. Can run on
small platform
s such as cell
phones.

The entire
database can actually be
sent
by

email as a file
attachment.


http://www.sqlite.org

Easy to learn, use and
manage.

Opensource.


ORACLE

EXAMPLE #######################################################################


// Oracle example // This example is
demonstrating
a
PHP page
using an Oracle Amazon RDS cloud instance.

**********************

Build the database on Amazon cloud first and then create and test all your pages from localhost.

The connection string will work

Must use Zend for Oracle..

If it works from your comput
er using localhost then deploy it to your Amazon Zend Server instance.

**********************


<!DOCTYPE html>

<html>

<head>

<style>



body {


background
-
image: url('../IMG_2874.jpg');

}


h2 {background
-
color:#8FBC8F;


color: white;

}




div.transbox


{


width:636px;


height:400px;


padding:14px;


overflow:scroll;


background
-
color:#F4F8F4;


border:1px solid black;


float left;





}


div.transbox p


{


margin:0px 40px;


font
-
weight:bol
d;


color:#000000;


}


div.menubox


{


width:160px;


height:400px;


float:left;


}


div.wrapper


{


margin:0px auto;


width:850px;


height: 420px;


background
-
color:#F4F8F4;


}


</style>


<title>Calcium<
/title>


</head>




<body>


<?php include 'header.php'; ?>


<h2> Garden Foods with highest amounts of CALCIUM</h2>


<center>


<div class="transbox">


<p> Average requirement of CALCIUM for people under age 50 is 1000 mg.<br/>A serv
ing of dairy(milk,yogurt or cheese) is
about 30% or 300mg of Calcium. </p><br/>




// *****above removed from other database PDO examples. *****




<?php


$conn = oci_connect('username', 'userpassword', 'yourOracleInstancename.yo
urmajicstringfromamazon.us
-
east
-
1.rds.amazonaws.com:1521/
xxxxxx
');


if (!$conn) {


$e = oci_error();


trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);


}




// connect to the topcalcium table and display


$stid = oci_parse($conn, 'SELECT displayline FROM topcalcium where rownum < 31 order by calcium desc');


oci_execute($stid);




echo "<table style='background
-
color:#F0FFF0;'border='4' cellspacing='20' cellpadding='3'>
\
n";


//echo "<table b
order='4'cellspacing='20' cellpading='3'>
\
n";


while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {


echo "<tr>
\
n";


foreach ($row as $item) {


echo " <td style='border
-
top:1px dashed #FFFFFF;'>" . ($item !== n
ull ? htmlentities($item, ENT_QUOTES) : "&nbsp;") .
"</td>
\
n";


}


echo "</tr>
\
n";


}


echo "</table>
\
n";


?>


// *****below removed from other database PDO examples. *****



<p> Average requirement of CALCIUM for people under age

50 is 1000 mg.


<a href="gardenfood_welcome.php">Home</a> <br/>


A serving of dairy(milk,yogurt or cheese) is about 30% or 300mg of Calcium.


</p>






</div>


<br/><br/><br/>

<br/><br/><br/><br/>

<?php include
'footer.php'; ?>


</center>



</body>




</html>



************************************************************************************************************


View the above Oracle example
PHP
page by going to
http://gardeneating.com



Select Best Nutrient Sources from top menu options and then select Calcium

*************************************************************************************************************







MyS
QL EXAMPLE #####
##################################################################


//MySql example // using localhost

********************


// removed the code above which was entirely the same as Oracle example above


// **********




<table style='back
ground
-
color:#F0FFF0;'border='4' cells
pacing='20' cellpadding='3'>


<?php

try {


$dbh = new PDO('mysql:host=127.0.0.1;dbname=gardenfood;charset=utf8','localtester','localpass');


foreach($dbh
-
>query('SELECT displayline from topcalcium') as $row) {


//print_r($row);


echo "<tr><td>".$row['displayline']."</td></tr>";


}

echo "</table>";


// close the database connection


$dbh = null;


// catch the PDO exception

} catch (PDOException $e) {


print "Error!: " . $e
-
>getMessage() . "
<br/>";


die();

}

?>


// removed lower non PDO related code of page. Bottom was entirely the same as Oracle example

.



//
http://php.net/manual/en/pdo.connections.php

SQL
ITE EXAMPLE #
######################################################################

// Sqlite example // *** using a
single
file inside of htdocs!

***********************

// removed the code above which was entirely the same as Oracle example above



<table
style='background
-
color:#F0FFF0;'border='4' cellspacing='20' cellpadding='3'>

<?php


try


{


//open the database


$db = new PDO("sqlite:gardeneating.db");


//in this example gardeneating.db i
s the name of a file in htdocs.


//NEW command opens or creates a sqlite databas
e,

if filename already exists it opens it if not it creates a new database.




$result = $db
-
>query('SELECT displayline from topcalcium limit 30');


foreach($result as $row)


{



echo "<tr><td>".$row['displayline']."</td></tr>";


}


echo "</table>";




// close the database connection


$db = NULL;


}


catch(PDOException $e)


{


print 'Exception : '.$e
-
>getMessage();


}



?>

// removed lower non PDO related code from page. Bottom code was entire
ly the same as Oracle example..