dynamic sql - binding to a select statment
Posted: Wed Apr 08, 2009 10:14 am
I've got this nasty feeling that this is undoable.
Simple put: Can you bind a string to an 'order by' in a select statement.
By the way col1 = varchar,
col2 = text,
col3 = int
On execution returns all values but 'order by' is ignored.
Mike in Toronto
Simple put: Can you bind a string to an 'order by' in a select statement.
Code: Select all
<?php
require_once ('./includes/connect_plsql.php');
$sql = 'select col1, col2, col3 from test_table [b]order by[/b] ?';
$stmt = $dbc->prepare($sql);
if ($dbc->errno <> 0) {
die($dbc->errno.' #1: '.$dbc->error.'<br />');
}
$stmt->bind_param('s', $orderby) or die($stmt->error);
$stmt->bind_result ($c1, $c2, $c3) or die ($stmt->error);
$orderby = "col1";
$stmt->execute();
if ($dbc->errno <> 0) {
die($dbc->errno.' #2: '.$dbc->error.'<br />');
}
while ($stmt->fetch())
echo '1: '. $c1 .' 2: '. $c2 .' 3: '. $c3 .'<br />';
?>
col2 = text,
col3 = int
On execution returns all values but 'order by' is ignored.
Mike in Toronto