2009-12-02 4 views
0

mysql을 mysql에서 mysql으로 변환하는 데 도움이 필요합니다.이 작업을 계속 수행하면서 오류가 계속 발생했습니다.이 작업을 수행하는 방법에 대한 기사를 읽고 여전히 작동하도록 할 수 있습니다.PHP 스크립트에서 MySQL을 MySQLI로 변환하는 데 도움이 필요합니까?

다음은 원본 작업 스크립트입니다.

<?php 

require_once ('./mysqli_connect.php'); // Connect to the db. 

if (isset($_POST['submitted'])) { 

if ($dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) { // Make the connnection. 

    if (!mysql_select_db (DB_NAME)) { // If it can't select the database. 

     // Handle the error. 
     trigger_error("Could not select the database!\n<br />MySQL Error: " . mysql_error()); 
     exit(); 

    } // End of mysql_select_db IF. 

} else { // If it couldn't connect to MySQL. 

    // Print a message to the user, include the footer, and kill the script. 
    trigger_error("Could not connect to MySQL!\n<br />MySQL Error: " . mysql_error()); 
    exit(); 

} // End of $dbc IF. 

// grab the tag 
$tag = mysql_real_escape_string($_POST['tag']); 

// see if the tag already exists and potentially what the current count is 
$query = "SELECT id, count, page FROM tags WHERE tag='$tag'"; 
$result = mysql_query($query); 

//--if there is a row, that means the tag exists 
if(mysql_num_rows($result)) 
{ 
//--pull out the tag ID and the current count and increment by one. 
    $tag_info = mysql_fetch_array($result); 
    $tag_info_id = $tag_info["id"]; 
    $tag_info_count = $tag_info["count"] + 1; 

//--update the table with the new count 
    $sql_update_cnt = "UPDATE tags SET count='$tag_info_count' 
          WHERE id='$tag_info_id'"; 
    mysql_query($sql_update_cnt); 

    echo "$tag now with $tag_info_count instances"; 
} 
else 
{ 
// tag is not there, so insert a new instance 
    $query = "INSERT INTO tags (tag, count) VALUES ('$tag', 1)"; 
if (!mysql_query($query, $dbc)) 
    { 
    die('Error: ' . mysql_error()); 
    } 
echo "1 record added"; 
} 
mysql_close($dbc); 
} 
?> 

내가 계속 오류가 있습니다.

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given on line 13 

Warning: mysqli_error() expects exactly 1 parameter, 0 given on line 16 
+0

모든 mysql을 mysqli로 변환. – bot

+1

가능한 중복 [Warning : mysql_fetch_ *은 매개 변수 1이 리소스가 될 것으로 예상하고, 부울은 주어진 오류 임] (http://stackoverflow.com/questions/11674312/warning-mysql-fetch-expects-parameter-1-to-be-resource) -boolean-given-error) – j0k

답변

0

그것은 mysqlimysql을 변경하는 모든 문제이다.

예를 들어 여기 mysql_query처럼 mysqli_query으로 전화 할 수 있습니다.

이러한 함수를 호출 할 때 첫 번째 매개 변수로 데이터베이스 참조를 전달해야합니다.

mysqli 함수 참조 here

+0

는 어떤 이유로 든 오류가 계속 발생하려고 했습니까? – bot

+0

어쩌면 어떤 오류가 발생했는지 알려주시겠습니까? –

+0

mysqli 레퍼런스를 첫 번째 매개 변수로 모든 절차 함수에 전달해야합니다! –

0

내가 mysql-> mysqli 변환 (2 삼년 등) 수행 한 이후 오랜만이야,하지만 IIRC 당신은 또한에 가지고있는 몇 가지 기능이 있습니다 참조 매개 변수 순서를 반대로하십시오. 사랑스럽지 않니?

0

번거 로움을 겪으려면 대신 PDO을 사용하는 것이 좋습니다.

관련 문제