Create a comma-separated string from a single column of an array of objects
Better: $resultstr = array(); foreach ($results as $result) { $resultstr[] = $result->name; } echo implode(“,”,$resultstr);
Better: $resultstr = array(); foreach ($results as $result) { $resultstr[] = $result->name; } echo implode(“,”,$resultstr);
The default for ResultSet.getInt when the field value is NULL is to return 0, which is also the default value for your iVal declaration. In which case your test is completely redundant. If you actually want to do something different if the field value is NULL, I suggest: int iVal = 0; ResultSet rs = … Read more
You should use the next statement first. ResultSet set = statement.executeQuery(); if (set.next()) { userName = set.getString(1); //your logic… } UPDATE As the Java 6 Documentation says A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes … Read more
You’ll need a beginner’s understanding of PHP, and probably some understanding of relational databases. Pagination is often implemented with some simple query parameters. stackoverflow.com/myResults.php?page=1 The page increments the query parameter: stackoverflow.com/myResults.php?page=2 On the back end, the page value usually corresponds to the limits and offsets in the query that is being used to generate the … Read more
I think you’re missing something here. This is how you can get multiple results from stored procedure using mysqli prepared statements: $stmt = mysqli_prepare($db, ‘CALL multiples(?, ?)’); mysqli_stmt_bind_param($stmt, ‘ii’, $param1, $param2); mysqli_stmt_execute($stmt); // fetch the first result set $result1 = mysqli_stmt_get_result($stmt); // you have to read the result set here while ($row = $result1->fetch_assoc()) { … Read more
I think there’s a way to use less memory (a fixed and not linear amount depending on data cardinality) but this imply to change the method signature. In fact we may print the Json data directly on an output stream as soon as we fetch them from the ResultSet: the already written data will be … Read more
You can’t access PLSQL objects (cases 2 & 5 = package-level objects) from java, see “java – passing array in oracle stored procedure”. You can however access SQL types (case 1 and 4). To get OUT parameters from PL/SQL to java, you can use the method described in one of Tom Kyte’s thread using OracleCallableStatement. … Read more
You can use foreach here just fine. foreach ($rows as $row) { echo $row[‘id’]; echo $row[‘firstname’]; echo $row[‘lastname’]; } I think you are used to accessing the data with numerical indices (such as $row[0]), but this is not necessary. We can use associative arrays to get the data we’re after.
json_encode is available in php > 5.2.0: echojson_encode($row);
Personally I’d use a pool as this will take care of all of the resource management for you. If your connection requirements change then you can easily modify the pool configuration. With a pool in place you can open/close connections and prepared statements according to best-practice and leave the resource management to the pool. Typically, … Read more