2011-04-20 6 views
-1
<?php 
$cons=mysql_connect("localhost","root",""); 
    mysql_select_db("infogallery") or die('Not Connected to the data base:'.mysql_error()); 
?> 

나는 MySQL의와 연결 코드 위에 쓰기하지만 난 MySQL의와의 연결을 위해 할 수있는 무엇 brouser에이 scripts..nothing 표시를 ... ... 실행할 때mysql이 PHP 스크립트에 연결되어 있지 않습니까?

+0

제로 upvotes 제로가 받아들입니다. – webbiedave

+1

제로 문법은 제로입니다. –

답변

1

는 연결하지 마십시오 루트 계정으로. 주변에서 놀기 위해 특별히 계정을 만듭니다. 다음과 같이 코드를 수정하는 것이 수행하면

:

$cons = mysql_connect('localhost', 'username', 'password'); 
if ($cons === FALSE) { 
    die("Failed to connect to MySQL: " . mysql_error()); 
} 
mysql_select_db(etc.....); 

연결이 실패하면 당신은 그 잠재적으로 실패한 연결에 대한 데이터베이스 작업을 수행하려고, 확인하지 않습니다. or die(...)에는 select 시도로 인한 오류 만 표시되며 실패한 연결의 오류 메시지는 손실됩니다.

3

아무 것도 표시되지 않으면 성공했음을 의미합니다. 데이터베이스를 쿼리하고 결과를 표시하는 코드를 추가하십시오.

0

난 그냥 다음과 같은 것에 대해

mysql_connect("localhost", "username", "password") or die(mysql_error()); 
mysql_select_db("infogallery") or die(mysql_error()); 
echo "So far, so good."; 
0

어떻게해야 좋아 :

<?php 
try { 
    $cons = mysql_connect("localhost","username","password"); 
} catch ($e) { 
    die('Failed to connect to the database: ' . mysql_error()); 
} 

try { 
    mysql_select_db("infogallery", $cons); 
} catch ($e) { 
    die('Failed to select the database: ' . mysql_error()); 
} 
?> 
관련 문제