Php PDO - 数据检索问题 [英] Php PDO - data retrieval issue

查看:77
本文介绍了Php PDO - 数据检索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的PDO脚本没有检索到任何结果都没有显示任何错误。



请有人指导我这里的错误是什么?



我的数据库连接文件,完全没有错误?



Hi Everone, my PDO script not retrieving any result neither showing any errors.

Please can someone guide me as to what the mistake I am doing here?

My DB Connection file, no errors at all?

<?php


	$db_host = "localhost";
	
	$db_name = "Office_E";
	$db_user = "root";
	$db_pass = "";
	
	try{
		
		$con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
		$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	}
	catch(PDOException $e){
		echo $e->getMessage();
	}


?>





我尝试了什么:





What I have tried:

<pre>?php
include 'config.php';

## Read value
$draw = $_POST['draw'];
$row = $_POST['start'];
$rowperpage = $_POST['length']; // Rows display per page
$columnIndex = $_POST['order'][0]['column']; // Column index
$columnName = $_POST['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_POST['order'][0]['dir']; // asc or desc
$searchValue = $_POST['search']['value']; // Search value

## Search 
$searchQuery = " ";
if($searchValue != ''){
	$searchQuery = " and (emp_no like '%".$searchValue."%' or 
        first_name like '%".$searchValue."%' or 
        last_name like'%".$searchValue."%' ) ";
}

## Total number of records without filtering - PDO style
// Count Total Records in the table
$totalRecords = $con->query("SELECT count(*) from employees")->fetchColumn();

## Total number of records with filtering - PDO Style
$totalRecordwithFilter = $con->query("SELECT count(*) from employees WHERE 1 ".$searchQuery)->fetchColumn();

## Fetch records - PDO style
$data = array();
// bind values..
$stmt = $con->prepare("select * from employees WHERE 1 ".$searchQuery." order by ".$columnName." ".$columnSortOrder." limit ".$row.",".$rowperpage;);
//$stmt->bindParam(1, $start,PDO::PARAM_INT);
//$stmt->bindParam(2, $end,PDO::PARAM_INT);
$stmt->execute();
$data1 = $stmt->fetchAll();

if ($stmt->fetchcolumn() > 0)
{
     
        foreach ($data1 as $row) {
        $data[] = array (
			"emp_no"=>$row['emp_name'],
    		"first_name"=>$row['first_name'],
    		"last_name"=>$row['last_name'],
    		"gender"=>$row['gender'],
    		"hire_date"=>$row['hire_date']
    	);
}
    unset($data1);
    
}

推荐答案

db_host =localhost;
db_host = "localhost";


db_name =Office_E;
db_name = "Office_E";


db_user =root;
db_user = "root";


这篇关于Php PDO - 数据检索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆