可能重複:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given errorPHP問題與數據庫連接
我有一類稱爲utils的這樣
class Utils
{
public static $connection;
function __construct()
{
}
public static function getConnection()
{
try
{
$connection = mysql_connect("localhost", "root", "robingraves");
mysql_select_db('repuesto_en_mano',$connection);
return $connection;
}
catch(Exception $e)
{
throw new Exception('Error connection with the data base');
}
}
public static function closeConnection ($conn)
{
mysql_close($conn);
}
}
而另一個類,使所謂的
require("Utils.php");
$utils = new Utils();
$connection = $utils->getConnection();
echo $connection;
$sqlCommand = 'Select IdMarca from Marca';
$resEmp = mysql_query($sqlCommand, $connection) or die(mysql_error());
$totEmp = mysql_num_rows($resEmp);
if ($totEmp> 0) {
while ($rowEmp = mysql_fetch_assoc($resEmp)) {
echo "<strong>".$rowEmp['IdMarca']."</strong><br>";
}
}
它說的
PHP的警告:請求mysql_query()預計 參數2是資源,空給出 在BrandsService.php第7行
我在做什麼錯
你是否檢查到你的MySQL數據庫的連接正在進行? – KJW