hey hey,

i am trying to connect to a mysql database on my local machine through the following script but nothing is shown, not even the error message. any idea why? ( i am logining as root to test for now ). thanks!

<?php    

@ $db = new mysqli('localhost', 'root', '******', 'work');

 if (mysqli_connect_errno()) {   
echo 'Error: Could not connect to database.'; exit;
} $query = "select * from projects"; $result = $db->query($query); $num_results = $result->num_rows; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); echo "<div>\n"; echo "<p class='sample'><a href='"; echo $row['link']; echo "/'>"; echo $row['name']; echo "</a>\n"; echo "-"; echo $row['description']; echo "</p>\n"; echo "</div>\n\n"; } $result->free(); $db->close(); ?>

Update 1:

i removed the @ and got this error message:

Fatal error: Class 'mysqli' not found in c:\Inetpub\wwwroot\mywork.php on line 60

do i need to install some php extension or something?? i have got php 5 installed. 😕

Update 2:

wooo! i've solved it. i just had to type in extension=php_mysqli.dll in my php.ini in the dll section. i am so proud of myself now... 😃

    "mysqli" (on line 3) is a class. You can't use it unless you have the class itself and include() it.

      thanks cheerio! solved it just now.

      hmm british?

      yeah me from the north.

        "mysqli" (on line 3) is a class. You can't use it unless you have the class itself and include() it.

        The mysqli class is an extension and does not need to be included(). I believe your problem to be this...

        if (mysqli_connect_errno()) {
        

        Needed to be....

        if ($db->errno()) {
        

          thanks thorpe. the problem was bcos i didn't enable the extension in php.ini.

            Write a Reply...