考虑以下代码:
<?php
$db_error='Establishing a Database Connection Error';
$localhost='localhost';
$db_user='root';
$db_name='uploader_db';
$db_pass='';
$db_connect=mysql_connect($localhost,$db_user,$db_pass) or die($db_error);
mysql_select_db($db_name) or die($db_error);
$result="SELECT 'user','pass','name','email' FROM 'config' ORDER BY 'name'";
$sql_result=mysql_fetch_array($result,MYSQL_BOTH);
echo $sql_count=count($sql_result['name']);
?>
我收到以下错误:
错误:警告:mysql_fetch_array()期望参数1为资源,第20行的C:\ xampp \ htdocs \ Project1 \ config.php中给出的字符串
0
我该如何解决这个问题?
最佳答案
您没有在代码中正确分配三件事
1)mysql_select_db($db_name)
:这里您需要通过$db_connect
2)不执行查询:$result=mysql_query($sql_fetch) or die("Error: ".mysql_error());
3)查询结果需要传递给mysql_fetch_array()
以下是具有上述更改的更新代码
$db_error='Establishing a Database Connection Error';
$localhost='localhost';
$db_user='root';
$db_name='uploader_db';
$db_pass='';
$db_connect=mysql_connect($localhost,$db_user,$db_pass) or die($db_error);
mysql_select_db($db_name,$db_connect) or die($db_error);
$sql_fetch="SELECT 'user','pass','name','email' FROM 'config' ORDER BY 'name'";
$result=mysql_query($sql_fetch) or die("Error: ".mysql_error());
$sql_result=mysql_fetch_array($result);
echo $sql_count=count($sql_result['name']);
关于php - 警告:mysql_fetch_array()期望参数1为资源…-为什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52681928/