이것은 사용할 것이다 나에게 지옥을 혼란 전혀 연결되지 않음
mysqli_connect($db_hostname, $db_username, $db_password)
mysql_select_db($db_database)
올바른 연결을 mysqli를 사용하여 데이터베이스에 확장하려면 (명백한 것은
$mysqli = new mysqli('localhost', 'fake_user', 'my_password', 'my_db');
if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}
당신은 documentation here
난 당신이 단순히 그것을 필요로하는 다른 스크립트 config.php
에서 연결을 사용할 수있는 추가하고 싶습니다 확인할 수 있습니다되지 않습니다 mysql_*
기능)이 그런 짓을하기 때문에 y를 더 사용할 수 있습니다.
require('config.php');
그래서 당신의 creatables.php
이
require("config.php");
$sql="CREATE TABLE quoter (
id int NOT NULL AUTO_INCREMENT,
quote text NOT NULL,
quoteby CHAR(50) NOT NULL,
PIMARY KEY (id)
)";
if (mysqli_query($mysqli,$sql))
{
echo "Table 'quoter' was created sucessfully";
}
else
{
echo "Error creating table 'quoter': ".mysqli_error($mysqli);
}
과 같이됩니다 config.php
$mysqli = new mysqli('localhost', 'fake_user', 'my_password', 'my_db');
if ($mysqli->connect_errno) {
die('Connect Error: ' . $mysqli->connect_errno);
}
난 당신이 통과해야하므로 $mysqli
매개 변수 느릅 나무 핸들 연결이므로주의 할 싶습니다 이 데이터베이스에서 작업을 수행하는 동안, 예 :
mysqli_query($mysqli,$sql);
//^here it is
config.php에서 연결하는 경우 왜 createtable.php에서 다시 연결하나요? – MatthewMcGovern
당신은 아주 좋은 지적을했지만 그것을 제거했지만 여전히 출력 중입니다 정의 된 데이터베이스를 선택할 수 없습니다 : 사용자 ''@ 'localhost'가 'testdb'데이터베이스에 액세스가 거부되었습니다. 이는 여전히 사용자 이름 루트를 보내지 못했다고합니다. 데이터베이스에 왜 이해가 안되는가 –
Fabio의 대답을 살펴보고 문제를 해결해야합니다. – MatthewMcGovern