警告:mysql_select_db()期望参数2是资源,

时间:2015-04-11 21:22:11

标签: mysql connection

<?php
$servername = "localhost";
$username = "root";
$password = "Rachel";
$db = "hairdressingapointments";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $db);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 
echo "Connected Sussessfully";
mysql_select_db('Hairdressingapointments', $conn) or die(mysql_error());
$sql = "SELECT `ApointmentDate`, `ApointmentTime` FROM `apointments` WHERE          `staff_id`=1 && `quantity`>0";
if(!mysql_query($sql)){
die('Error: ' . mysql_error());
}
echo $sql;

mysql_close();

?>

花了好几个小时试图解决这个问题并且我猜测它的东西如此简单。找回以下错误:   警告:mysql_select_db()期望参数2是资源,第15行的C:\ wamp2 \ www \ hairdressingapointments \ TeresaApointments.php中给出的对象,

mysql_select_db('Hairdressingapointments', $conn) or die(mysql_error());

1 个答案:

答案 0 :(得分:0)

  1. 您已使用

    连接到数据库

    mysqli_connect(...);

    所以,你不需要

    mysql_select_db(....);

  2. 同时将查询更改为此

    $ sql =“SELECT ApointmentDate,ApointmentTime FROM apointsments WHERE staff_id = 1 AND quantity&gt; 0”;

    如果您使用SQLWorkbench或SQLYog或其他工具,您可以输入SQL并确保它在将其添加到脚本之前有效。

  3. 另外,请确保表名真的是

  4.   

    apointments

    而不是

      

    约会

    我从php.net - mysqli_connect

    获得了这些信息