本文目錄一覽:
- 1、PHP如何連接oracle資料庫
- 2、還是那個php問題
- 3、php怎麼始終連接不上ORACLE啊,有誰能幫幫我啊,phpinfo也顯示支持oci8,oracle版本為9.2.0.1.0
- 4、求PHP與ORACLE資料庫連接的代碼
- 5、請問PHP如何取資料庫中sequence的nextval值到一個變數?
PHP如何連接oracle資料庫
首先你要在php.ini文件中找到
extension=php_oci8.dll 前面的注釋符號「;」去掉,使php能夠載入支持oracle的模塊;
下面的代碼是調試通過的,可直接使用的:
html
body
?php
$dbconn=OCILogon(“root”,”pass”,”(DESCRIPTION=(ADDRESS=(PROTOCOL =TCP)(HOST=遠程IP)(PORT = 1521))(CONNECT_DATA =(SID=GZXNCW)))”);
if($dbconn!=false)
{
echo “連接成功”;
if(OCILogOff($dbconn)==true)
{
echo “關閉連接成功!”;
}
}
else
{
echo “連接失敗”;
}
?
/body
/html
?php
$dbconn=oci_connect(“你的賬號”,”你的密碼”,”你的資料庫名稱”);//請把中文件設置為你的值;
$stmt=oci_parse($dbconn, “select * from scott.hallo”);
oci_execute($stmt, OCI_DEFAULT);
echo $conn.”—-selecting\n\n”;
while (oci_fetch($stmt))
{
echo ($conn.”[“.oci_result($stmt, “TEST”).”]\n\n”);
}
echo ($conn . “—-done\n\n”);
?
還是那個php問題
你其他程序可以運行成功? ,我過會運行下試試,等等
錯誤在這裡:
「select sum(qty_stock*unit_cost) from Part;「
執行語句結尾不能像mysql那樣寫,以」;「來執行多條語句
應該去掉」;「:「select sum(qty_stock*unit_cost) from Part「
建議:
你使用的oci函數最好改為最新的名字就,以下來自php手冊
ocilogoff — 別名 oci_close()
Report a bug
reject note 說明
Warning
自 PHP 5.4.0 起,已經廢棄此別名。強烈建議不要應用此別名 。
php怎麼始終連接不上ORACLE啊,有誰能幫幫我啊,phpinfo也顯示支持oci8,oracle版本為9.2.0.1.0
我曾經裝過10G的php連接ord。
程序運行必須步驟如下
1.安裝orl client
2.修改php.ini,打開php_oci.dll等擴展dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll
extension=php_oci8.dll
extension=php_oracle.dll
?php
@header(“Content-Type: text/html; charset=gb2312”);
$conn = oci_connect(‘name’, ‘pass’, ‘ordclientdbname’,’ZHS16GBK’);//SIMPLIFIED CHINESE_CHINA.ZHS16GBK AMERICAN.UTF8
if (!$conn) {
$e = oci_error();
print htmlentities($e[‘message’]);
exit;
}
$query = ‘SELECT * FROM taobaogoods’;
$stid = oci_parse($conn, $query);
if (!$stid) {
$e = oci_error($conn);
print htmlentities($e[‘message’]);
exit;
}
$r = oci_execute($stid, OCI_DEFAULT);
if(!$r) {
$e = oci_error($stid);
echo htmlentities($e[‘message’]);
exit;
}
print ‘htmlmeta http-equiv=”Content-Type” content=”text/html; charset=gb2312″bodytable border=”1″‘;
$i =0;
while($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
print ‘tr’;
foreach($row as $item) {
// if($i ==3)echo “script alert(‘$item’);/script”;
print ‘td’.($item ? $item:’ ‘).’/td’;
//print ‘td’.($item ? iconv(‘utf-8′,’gb2312′,htmlentities($item)):’ ‘).’/td’;
}
$i++;
//exit;
print ‘/tr’;
}
print ‘/table/body/html’;
oci_close($conn);
exit;
求PHP與ORACLE資料庫連接的代碼
強烈推薦使用ADODB庫鏈接資料庫。
如果一定要使用PHP內置函數,那麼:
如果PHP版本5.0,那麼使用下面的函數
oci_connect
(
username,
password
,
dbname
)
例子:
?php
$conn
=
oci_connect(‘hr’,
‘hr’,
‘orcl’);
//
建立連接
if
(!$conn)
{
$e
=
oci_error();
htmlentities($e[‘message’]);
exit;
}
$query
=
‘SELECT
*
FROM
DEPARTMENTS’;
//
查詢語句
$stid
=
oci_parse($conn,
$query);
//
配置SQL語句,準備執行
if
(!$stid)
{
$e
=
oci_error($conn);
htmlentities($e[‘message’]);
exit;
}
$r
=
oci_execute($stid,
OCI_DEFAULT);
//
執行SQL。OCI_DEFAULT表示不要自動commit
if(!$r)
{
$e
=
oci_error($stid);
echo
htmlentities($e[‘message’]);
exit;
}
//
列印執行結果
‘table
border=”1″‘;
while($row
=
oci_fetch_array($stid,
OCI_RETURN_NULLS))
{
‘tr’;
foreach($row
as
$item)
{
‘td’.($item?htmlentities($item):’ ‘).’/td’;
}
‘/tr’;
}
‘/table’;
oci_close($conn);
?
請問PHP如何取資料庫中sequence的nextval值到一個變數?
$cx=”select seq_id.nextval as seq from dual”;
$conn-query($cx);
while($conn-next_record()){
$seq_id=$conn-f(“seq”);
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/288811.html