my db connection approach is total wrong. its not related to path, its related to the db connection.
i passed the db handle to the function as parameter and now it works.
function get_position_by_id($position_id,$db){
.......
}
Glad you have it working, here’s how to do it using prepared statement:
<?php
function get_position_by_id($position_id, $db) {
$query="SELECT *
FROM positions
WHERE position_id=:id";
/* Prepare the query */
$stmt = $db->prepare($query);
/* Execute the query with the prepared statement */
$stmt->execute(array(':id' => $position_id));
/* Fetch the results */
$result = $stmt->fetch(PDO::FETCH_ASSOC);
/* Return the result */
return $result['position'];
}
A function that makes use of a database connection should receive the database as an argument, otherwise the code is rendered untestable due to outside dependencies. Functions that issue require statements should be few and far between - template parsing functions and class loaders for the most part.