100 Web Space
http://forum.100webspace.com/

Accessing MySQL using PHP
http://forum.100webspace.com/viewtopic.php?f=5&t=5706
Page 1 of 1

Author:  jesarr [ Fri Jan 05, 2007 5:00 am ]
Post subject:  Accessing MySQL using PHP

Greetings, all! I'm new to PHP and am using 100 Web Space as a platform to educate myself along with "PHP & MySQL for Dummies". I've managed to get a few test scripts to run in PHP, small successes, but now I've entered the database testing code (found below) and get the error: "Fatal error: Call to undefined function: mysqli_connect() in /home/www/jesarr.100webspace.net/dbtest.php on line 12" which has me nonplussed. I created a MySQL database via the control panel in my account menu, named it and created a password, so it's there. I also tried setting the $host variable equal to "localhost" but that didn't help. My current assumption is that I'm entering an invalid host address, but I'm new, so I'm not too sure. If that isn't the correct host address, btw, can anyone tell me what I ought to be entering? Thanks for your responses, although I know C++ (which is very similar to PHP) a lot of this MySQL stuff is rough.


Code:
<?php
echo "<html>
    <head>
        <title>Test MySQL</title>
    </head>
    <body>";

        $host="mysql1.100ws.com";
        $user="user";
        $password="password";

        $cxn = mysqli_connect($host,$user,$password);
        $sql="SHOW STATUS";
        $result = mysqli_query($cxn,$sql);
        if($result == false)
        {
        echo "<h4>Error: ".mysqli_error($cxn)."</h4>";
        }
    else
{
/*Table that displays the results*/
echo "<table border='1'>
                <tr><th>Variable_name</th>
                    <th>Value</th></tr>";
     for($i = 0; $i < mysqli_num_rows($result); $i++)
         {
              echo "<tr>";
              $row_array = mysqli_fetch_row($result);
               for ($j = 0; $j < mysqli_num_fields($result); $j++)
           {
              echo "<td>".$row_array[$j]."</td>\n";
           }
        }
        echo "</table>";
      }
?>
</body></html>

Author:  jesarr [ Sat Jan 06, 2007 6:44 am ]
Post subject: 

Thanks a lot. Upon tweaking, trial and error, reading other posts in the forums, and skipping a few chapters ahead in the book I'm using, I managed to string together this code (which works!). Huzzah!

Code:
<?php
echo "<html>
    <head>
        <title>Test MySQL</title>
    </head>
    <body>";

        $host="mysql1.100ws.com";
        $user="jesarr_test";
        $password="password";

        mysql_connect($host,$user,$password);
        mysql_select_db(jesarr_test);
        $sql="SHOW STATUS";
        $result = mysql_query($sql);
if($result == false)
{
     echo "<h4>Error: ".mysql_error($cxn)."</h4>";
}
else
{
/*Table that displays the results*/
echo "<table border='1'>
                <tr><th>Variable_name</th>
                    <th>Value</th></tr>";
     for($i = 0; $i < mysql_num_rows($result); $i++)
         {
              echo "<tr>";
              $row_array = mysql_fetch_row($result);
               for ($j = 0; $j < mysql_num_fields($result); $j++)
           {
              echo "<td>".$row_array[$j]."</td>\n";
           }
        }
        echo "</table>";
      }
?>
</body></html>

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/