[英]What is wrong with this PHP function?
I wrote a PHP function to query a database and return the complete result set but it's not working (I get no results). 我写了一个PHP函数来查询数据库并返回完整的结果集,但是它不起作用(我没有得到结果)。 I'm new to PHP, am I using the function properly?
我是PHP新手,是否可以正确使用该函数?
<?php
$sql = array(
'user' => 'user',
'password' => 'pass',
'server' => '10.10.10.10',
'db' => 'XE'
);
$conn = oci_connect($sql['user'], $sql['password'], $sql['server'].'/'.$sql['db']);
if (!$conn) {
$e = oci_error();
trigger_error( htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR );
}
function db_query( $conn, $bindings, $query )
{
$stmt = oci_parse( $conn, trim($query) );
foreach ($bindings as $key => $value) {
if ( strpos( $query, $key) ) {
oci_bind_by_name( $stmt, $key, $value );
}
}
oci_execute( $stmt );
oci_fetch_all( $stmt, $data );
oci_free_statement( $stmt );
return $data;
}
$bindings = array();
$query = 'SELECT COUNT(*) FROM Orders';
echo db_query();
?>
//Set your bindings
$bindings = array();
//Set your Query
$query = 'SELECT COUNT(*) FROM Orders';
//Fire it up and store the result in $data
$data = db_query( $conn, $bindings, $query );
//Dump $data to see whats inside
var_dump($data);
This should help you... If $data returns NULL, make sure the query is correct, the databasetable is filled with data and the database connection is successful. 这应该可以帮助您...如果$ data返回NULL,请确保查询正确,databasetable中已填充数据,并且数据库连接成功。
Steps: 脚步:
update your code 更新您的代码
dump $data and check the result 转储$ data并检查结果
check the databse connection 检查数据库连接
check the databasetable 检查数据库表
have a drink... 喝一杯(酒...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.