在通过XAMPP在localhost上进行开发时,我在代码中使用了mysqli_fetch_all。但在godaddy共享主机上传后,它无法正常工作。
我在互联网上研究并发现服务器应该使用MySQLnd来运行mysqli_fetch_all。所以我无法在服务器上运行我当前的代码。
我需要这个代码的确切替代品。有什么建议吗?
当前代码:
$result = mysqli_query($con,$query);
$arr = mysqli_fetch_all($result, MYSQLI_ASSOC);
$totalrecords = count($arr);
$json = array('sEcho' => '1', 'iTotalRecords' => $totalrecords, 'iTotalDisplayRecords' => $totalrecords, 'aaData' => $arr);
echo json_encode($json );
答案 0 :(得分:4)
如果由于您没有安装mysqlnd而无法使用它,那么就像通常使用mysqli_fetch_assoc()
$arr = array();
$result = mysqli_query($con,$query);
$totalrecords = mysqli_num_rows($result);
while($row = mysqli_fetch_assoc($result)) {
$arr[] = $row;
}
$json = array('sEcho' => '1', 'iTotalRecords' => $totalrecords, 'iTotalDisplayRecords' => $totalrecords, 'aaData' => $arr);
echo json_encode($json);
答案 1 :(得分:0)
我遇到了与我的主机相同的问题,并且为了减少代码重构,我认为更好的方法是使用mysqli_fetch_all()
或public function mysqli_fetch_all_alt($result) {
$select = array();
while( $row = mysqli_fetch_assoc($result) ) {
$select[] = $row;
}
return $select;
}
实现类似的功能,返回与{{1}相同的功能},
像:
def newPoly3D(self):
from matplotlib.cm import autumn
# This passes a pandas dataframe of shape (data on rows x 4 columns)
df = self.loadData()
fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
vels = [1.42,1.11,0.81,0.50]
which_joints = df.columns
L = len(which_joints)
dmin,dmax = df.min().min(),df.max().max()
dix = df.index.values
offset=-5
for i,j in enumerate(which_joints):
ax.add_collection3d(plt.fill_between(dix,df[j],
dmin,
lw=1.5,
alpha=0.3/float(i+1.),
facecolor=autumn(i/float(L))),
zs=vels[i],
zdir='y')
ax.grid(False)
ax.set_xlabel('A')
ax.set_xlim([0,df.index[-1]])
ax.set_xticks([])
ax.xaxis.set_ticklabels([])
ax.set_axis_off
ax.set_ylabel('B')
ax.set_ylim([0.4, max(vels)+0.075])
ax.set_yticks(vels)
ax.tick_params(direction='out', pad=10)
ax.set_zlabel('C')
ax.set_zlim([dmin,dmax])
ax.xaxis.labelpad = -10
ax.yaxis.labelpad = 15
ax.zaxis.labelpad = 15
# Note the inversion of the axis
plt.gca().invert_yaxis()
然后在项目中执行find-replace。