无法建立联系

时间:2014-04-21 00:07:31

标签: php database

无法建立连接,因为目标计算机主动拒绝它。

这是我的代码。     

    //$db = 'htdocs\as4.mdb';

    //$conn = new COM('ADODB.Connection');

    mysql_connect('htdocs\as4.mdb');
    mysql_select_db('vendor');

    $search = $_POST['search'];

    $sql = "SELECT * FROM vendor WHERE vendorName like '%search%' OR 
                address like '%search%' or
                city like '%search%' or
                provState like '%search%' or
                country like '%search%'";

    $result = mysql_query($sql, $conn) or die (mysql_error());

    $number = mysql_num_rows($result);
   // <h3>$number of results found search for "$search"</h3>

    while($row = mysql_fetch_array($result))
    {
        $vendorName = $row['vendorName'];
        $address = $row['address'];
        $city = $row['city'];
        $provState = $row['provState'];
        $country = $row['country'];
    }


?>

我尝试连接到数据库,并通过搜索文本框找到某个关键字,并显示与关键字有关的任何内容的结果,例如,如果我在加拿大输入,我希望看到加拿大所有人的结果。我尝试通过新的COM(&#39; ADODB.Connection&#39;)进行操作,因为您可以看到它被注释掉了,但无法确切地知道如何。

如果我想使用这样的东西来搜索数据库怎么办?

$db = 'htdocs\database\database.mdb';
$sql = "SELECT * FROM Vendor";

//to make this work, you need to add
//extension=php_com_dotnet.dll
//to your php.ini file. Put it with the other
//extension=
//values towards the bottom of the file (around line number 1050)
$conn = new COM('ADODB.Connection');

if(!$conn)
{
    echo "Database unreachable";
    exit();
}
else
{
    echo "Success!<hr />";

    try
    {
        $conn -> Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
        $rs = $conn->Execute($sql);
    }
    catch(Exception $e)
    {
        echo 'Caught exception: ', $e->getMessage(), "<br />";
        exit();
    }

    while(!$rs->EOF)
    {
        For($i = 0; $i < ($rs->Fields->Count); $i++)
        {
            echo $rs->Fields[$i]->Value;
            echo " ";
        }
        echo "<br />";
        $rs->MoveNext();
    }

0 个答案:

没有答案