Reputation: 485
I am trying to create a view from another view from php and im not getting any error but it simple does not create a view. I can manually create view from another in the mysql console but not from php. Any idea where I am going wrong?
function createTransaction_file($db,$file_id){
$sql = "CREATE VIEW transaction_file AS SELECT context,transaction_type,starttime,stoptime,stoptime - starttime AS runtime,correlator,parent_correlator,iteration FROM transactions WHERE file_id =" . $file_id . " ORDER BY starttime" ;
//echo $sql;
if($stmt = $db->prepare($sql)){
/* execute query */
$stmt->execute();
}else{
echo "File id is ". $file_id;
echo "Error code ({$db->errno}): {$db->error}";
die("Could not create transaction_iter view");
}
/* close statement */
$stmt->close();
}
function createTransaction_iter($db,$iteration){
$sql = "CREATE VIEW transaction_iter AS SELECT context,transaction_type,starttime,stoptime,stoptime - starttime AS runtime,correlator,parent_correlator,iteration FROM transaction_file WHERE iteration = ".$iteration." LIMIT 500;" ;
//echo $sql;
if($stmt = $db->prepare($sql)){
/* execute query */
$stmt->execute();
}else{
echo "File id is ". $file_id;
echo "Error code ({$db->errno}): {$db->error}";
die("Could not create transaction_iter view");
}
/* close statement */
$stmt->close();
}
createTransaction_file($db,$file_id);
createTransaction_iter($db,$iteration);
Upvotes: 2
Views: 1442
Reputation: 7054
I think you are simply not getting the details of the error back. Again, that if/else block is not what you meant to do I believe. Try something like this:
$stmt = $db->prepare($sql);
if (! $stmt->execute()) {
$arr = $stmt->errorInfo();
print_r($arr);
}
UPDATE: So as expected that error message suggests a lack of required permissions for your user. I'm guessing your views were created with different rights. Here is a similar SO posting: mysql forgets who is logged in: command denied to user ''@'%' that discusses how you can get insight into the rights of those views/tables.
Upvotes: 1