- 初学请教大家:php+mysql连接问题?
一个简单的登录画面,选择部门后,筛选该部门的用户,写这个getuser.php文件的时候,如果采用include "conn.php";这种方式连接数据库的话,电脑上测试是能读到用户给picker的,但是测试版或者真机调试时,picker只能读出一堆null了,但是真机调试,在Network菜单下看到数据确实已经取到了。如果把连接写死在这个文件里,就完全没问题。很疑惑,请帮忙看看.因为好些个文件都有类似错误,所以得改动多个文件比较麻烦,所以来求助大家 以下这样出错: include "conn.php"; if (!$con){ die('Could not connect: ' . mysqli_connect_error());} mysqli_query($con,"set names utf8"); $dept = $_GET['dept']; $grade=$_GET['grade']; $sql1=" select * from user where dept='$dept' and grade=1 order by username ;"; $result1 = mysqli_query($con,$sql1); $data=$result1->fetch_all(PDO::FETCH_LAZY); echo json_encode($data); mysqli_close($con); 以下这样没问题: header("Content-Type: text/html;charset=utf-8"); $con=mysqli_connect("150.xx.xx.xx","wx","xxxxxxxx","xxx"); if (!$con){ die('Could not connect: ' . mysqli_connect_error());} mysqli_query($con,"set names utf8"); $dept = $_GET['dept']; $grade=$_GET['grade']; $sql1=" select * from user where dept='$dept' and grade=1 order by username ;"; $result1 = mysqli_query($con,$sql1); $data=$result1->fetch_all(PDO::FETCH_LAZY); echo json_encode($data); mysqli_close($con); conn.php如下: header("Content-Type: text/html;charset=utf-8"); $con=mysqli_connect("150.xx.xx.xx","wx","xxxxxxx","xxx"); if (!$con) { die('Could not connect: ' . mysqli_connect_error()); } mysqli_query($con,"set names utf8"); 写picker部分是这样: success: function (res) { var array = res.data; // var username = []; var length = array.length; for (var i = 0; i < length; i++) { username.push(array[i].username) } if (username.length > 0) { userpick = username[userindex]; } that.setData({ array: array, username: username, userindex: userindex }) }
2022-03-30 - 小程序连PHP时抛出错误,必须降PHP版本吗?
php版本是7.2,出现了如下错误 Use of undefined constant XXXXXXX - assumed 'XXXXX' (this will throw an Error in a future version of PHP) 网上查了些,可能要将PHP版本降成5.6,或者装多个版本PHP切换也可以, Warning: Use of undefined constant datelist - assumed 'datelist' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\stbc\apply.php on line 6 PHP第六行很简单 就是:$datelist=$_POST[datelist];
2022-03-05