php 连接oracle

https://blog.csdn.net/qq_34221812/article/details/85269781

https://www.cnblogs.com/semonxv/p/3831573.html

 

解决乱码问题:

连接时 设置编码:$conn = oci_connect("C##SCOTT", "tiger",$db,'utf8');

绑定数据时候中文转码:mb_covert_encoding($data,'GBK','UTF-8');

 

plsql 操作数据库:

select * from user_constraints where table_name='表名字,必须大写';                    //通过sql去查询这个表的约束

select userenv('language') from dual;                         //查看字符集

sql语句select * from V$NLS_PARAMETERS查看本地字符集,查看第一行和第九行是否对应

 

 

 

oci 操作 oracle 数据库:

public function select(){
//echo phpinfo();die();
$conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');

if($conn){
echo "connect success";
echo '
';
}else{
echo "connect error";
echo '
';
}
$sql = "select * from or_student";
$ora_test = oci_parse($conn,$sql); //编译sql语句
oci_execute($ora_test,OCI_COMMIT_ON_SUCCESS); //执行

//1、第一种
$rr = oci_fetch_all($ora_test,$r);

//2、第二种
//$r = oci_fetch_array($ora_test, OCI_BOTH);

foreach($r as $rows){
echo "";echo '
';
foreach($rows as $col_values){
echo $col_values.'/';
}
}
echo '
';echo '
';
var_dump($r);
//var_dump($rr);

//释放资源
oci_free_statement($ora_test);
oci_close($conn);
}

public function add1(){
$conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');
$query="insert into or_student(S_ID,S_NAME,S_SEX) values(:S_ID,:S_NAME,:S_SEX)";
$statement=oci_parse($conn,$query);

$S_ID='8';
$S_NAME='qq';
$S_SEX='';

oci_bind_by_name($statement,":s_id",$S_ID);
oci_bind_by_name($statement,":s_name",$S_NAME);
oci_bind_by_name($statement,":s_sex",$S_SEX);



//执行语句,设置执行模式为自动提交
oci_execute($statement,OCI_COMMIT_ON_SUCCESS);
//检查影响的行数

echo "插入成功:".oci_num_rows($statement);


//释放资源
oci_free_statement($statement);
oci_close($conn);

}

public function add2(){
$conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');
$query="insert into or_student(s_id,s_name,s_sex) values(9,'第七','')";
$statement=oci_parse($conn,$query);

//执行语句,设置执行模式为自动提交
oci_execute($statement,OCI_COMMIT_ON_SUCCESS);
//检查影响的行数

echo "插入成功:".oci_num_rows($statement);

//释放资源
oci_free_statement($statement);
oci_close($conn);

}



public function delete(){

$conn = oci_connect('scott','Wcs123456','127.0.0.1/orcl');
$query="delete from or_student where S_ID=5";
$statement=oci_parse($conn,$query);


//执行语句,设置执行模式为自动提交
oci_execute($statement,OCI_COMMIT_ON_SUCCESS);
//检查影响的行数

echo "删除成功:".oci_num_rows($statement);


//释放资源
oci_free_statement($statement);
oci_close($conn);


}

你可能感兴趣的:(php 连接oracle)