我是PHP新手。我现在要做的就是从MySQL服务器调用存储过程。我能够使用标准的SELECT语句成功查询数据库,但是当我尝试调用存储过程时,它永远不会工作。如果我将$ sql换成标准的SELECT * FROM表,它就可以了。我到处寻找。但无法弄清楚该怎么做。我哪里错了?
<?php
$servername = server;
$username = username;
$password = password;
$dbname = databasename;
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else {
echo "It worked!<br/><br/>";
}
if(mysqli_ping($conn) != null) {
echo "Connection is open!<br/><br/>";
$sql = "CALL GetUserTypes";
$result = $conn->query("$sql");
if ($result != null) {
$i = 0;
$row = mysqli_fetch_row($result);
while ($row = $result->fetch_assoc()) {
echo '<p>' . $row['id']. " " . $row['type'] . '</p>';
$i++;
}
}
elseif (is_null($result)) {
echo "Something broke...<br/>";
}
else {
echo "Query did not work...<br/>";
}
$con->close();
else {
echo "No connection...";
}
?>