Prepared Statement getting Commands out of sync; you can't run this
command now
I have read everything I can think of to get an explanation but nothing
seems to help. If someone might be able to point out the obvious or give
me a slight idea of what is wrong. I have read through php.net and the
mysqli tag and can't seem to figure this out. Everything I read says you
can't send two queries but I am only trying one. Any help would be much
appreciated.
This->http://stackoverflow.com/a/9649149/1626329 - States that maybe I
have multiple result sets but I am not sure that makes much sense or what
I can do to get more detail on the inner workings of prepared statements.
The Code:
date_default_timezone_set('America/Phoenix');
class mydb {
public function __construct() {
// Connect to Database
$this->mydb = new mysqli('****', '****', '****', '****');
if ($this->mydb->connect_errno) { // Error on connection failure
echo "Failed to connect to MySQL in Construct: (" .
$this->mydb->connect_errno . ") " .
$this->mydb->connect_error;
}
return $this->mydb;
}
public function choose ($select, $from, $config = 0, $options = NULL) {
if ($config === 0) { /** Configure statement for prepare depending
on options */
$stmt = 'SELECT ? FROM ' . filter_var($from,
FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
} elseif ($config === 1) {
$stmt = 'SELECT ? FROM ' . filter_var($from,
FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES) . '
WHERE ? LIKE ?';
} elseif ($config === 2) {
$stmt = 'SELECT ? FROM ' . filter_var($from,
FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES) . '
WHERE ? = ?';
} else {
echo 'Config did not match: ' . $mydb->error . '<br/>';
} /** End if/elseif Prepare statemenet */
$mydb = $this->mydb->prepare($stmt);
if ($config === NULL) { /** Bindings for execute based on options */
$mydb->bind_param("s",$select);
} elseif ($config === 1 || $config === 2) {
$mydb->bind_param("sss",$select,$options['where_comp'],$options['']);
} else {
echo 'Did not Bind_parameters: ' . $mydb->error . '<br/>';
} /** End if bindings */
if ($mydb->execute()) { /** If execute is good then get results */
$result = $mydb->get_result();
$payload = array();
while ($row = $result->fetch_array(MYSQLI_NUM)) {
$payload[] .= $row;
}
return $payload;
} /** End if results */
} /** End choose class method */
} /** End mydb Class */
$myDB = new mydb();
$agentArray = $myDB->choose('*','`agent`',2,array('where_comp' =>
'`team`','where_value' => 'Second Shift Tech'));
No comments:
Post a Comment