<?php include "header.php";
$con = mysqli_connect("localhost","root","","edu");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
//echo "connection successful";
}
?>
<style type="text/css">
.dataTables_filter { float: right; }
</style>
<div class="container-fluid">
<div class="row">
<div class="form-group row" style="width: 95%; margin: auto; margin-bottom: 20px;">
<form method="post" id="FORM1">
<div class="form-group row well" style="margin: auto; margin-bottom: 20px; border-color: black; background-color: white;">
<div class="col-sm-12" >
<div style="color: green; font-weight: bold; font-size: 21px; ">SQL Query:</div>
</div>
<textarea class="form-control" rows="5" name="query"><?php if(isset($_POST['execute'])){echo $_POST['query'];}?></textarea>
<div style="color: green; font-weight: bold; font-size: 21px; text-align: right; margin-top: 10px;"> <input type="submit" name="execute" class="btn btn-warning" value="Execute" style="width: 120px; margin-right: 10px;" /></div>
</div>
<?php //echo $_SESSION['insert_msg']; ?>
</form>
<?php
if(isset($_POST["execute"]))
{
$sql=$_POST['query'];
if ((strpos($sql, 'UPDATE') !== false) || (strpos($sql, 'update') !== false) || (strpos($sql, 'delete') !== false) ||(strpos($sql, 'DELETE')) !== false)
{
if((strpos($sql, 'WHERE') <= 0) || (strpos($sql, 'where') <= 0))
{
echo '<div class="alert alert-danger"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a> Use "WHERE" clause while using UPDATE and DELETE statement</div>';
}
else
{
$result1=mysqli_query($con,$sql);
if($result1)
{
$affected_rows=mysqli_affected_rows($con);
echo '<div class="alert alert-info"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a> Affected Rows '.$affected_rows.'</div>';
}
else
{
echo '<div class="alert alert-danger"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a>'.mysqli_error($con).'</div>';
}
}
}
else if((strpos($sql, 'SELECT') !== false) || (strpos($sql, 'select') !== false))
{
$result1=mysqli_query($con,$sql);
if($result1)
{
$rowcount=mysqli_num_rows($result1);
echo '<div class="alert alert-info"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a> Found Rows: '.$rowcount.'</div>';
$result=mysqli_fetch_all($result1,MYSQLI_ASSOC);
?>
<div class="form-group row well" style="margin: auto; margin-bottom: 20px; border-color: black; background-color: white;">
<div class="col-sm-12">
<div style="color: green; font-weight: bold; font-size: 21px; ">Output:</div>
<div class="col-sm-12" style="border: solid 1px #8d8080; max-height: 550px; min-height: 250px; height: 100%; width: 99%; margin: auto; margin-bottom: 10px; padding-top: 10px; overflow: scroll;">
<table class="table table-bordered">
<tr>
<?php
// Take the keys from the first row as the headings
foreach (array_keys($result[0]) as $heading)
{
echo '<th>' . $heading . '</th>';
}
echo "</tr>\n";
// The body
foreach ($result as $row)
{
echo "\t<tr>" ;
foreach ($row as $cell)
{
echo '<td>'.$cell;
echo '</td>';
}
echo "</tr>\n";
}
?>
</table>
</div>
</div>
</div>
<?php }
else{
echo '<div class="alert alert-danger"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a>'.mysqli_error($con).'</div>';
}
}
else if((strpos($sql, 'INSERT') !== false) || (strpos($sql, 'insert') !== false))
{
$result1=mysqli_query($con,$sql);
if($result1)
{
$affected_rows=mysqli_affected_rows($con);
echo '<div class="alert alert-info"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a> Total '.$affected_rows.' Rows Inserted.</div>';
// header("refresh: 5;location:".STATE_PATH."/query_editor.php");
header("Refresh: 2; url=query_editor.php");
//echo $_SESSION['insert_msg'];
}
else
{
echo '<div class="alert alert-danger"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a>'.mysqli_error($con).'</div>';
}
}else if((strpos($sql, 'CREATE') !== false) || (strpos($sql, 'create') !== false))
{
$result1=mysqli_query($con,$sql);
if($result1)
{
echo '<div class="alert alert-success"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a> Table created successfully.</div>';
}
else
{
echo '<div class="alert alert-danger"><a class="close" data-dismiss="alert" style="float:right;
cursor:default; font-weight:bold">x</a>'.mysqli_error($con).'</div>';
}
}
}?>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$.validator.messages.required = "";
addValidator();
$("#FORM1").validate({
rules: {
fromdt: { date_hyphen: true, required: true },
todt: { date_hyphen: true, required: true, greaterThan: "#fromdt" },
},
messages: {
}
});
});
</script>
<?php include "report_footer.php"; ?>
您好,我正在创建查询编辑器,并且在玛丽亚数据库的72行number.my数据库中出错。行计数代码工作正常,但第72行出错。
我有错误$result=mysqli_fetch_all($result1,MYSQLI_ASSOC);
此行。请帮帮我。谢谢你。
答案 0 :(得分:0)
也许您的PHP 5.3.0。版本导致问题。您的版本可能较旧。
请改用fetch_assoc()
while ($row = $result->fetch_assoc()) {
// do what you need.
}