It is currently Fri Mar 29, 2024 8:27 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Accessing MySQL using PHP
PostPosted: Fri Jan 05, 2007 5:00 am 
Noobie
Noobie

Joined: Fri Jan 05, 2007 4:48 am
Posts: 2
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>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 6:44 am 
Noobie
Noobie

Joined: Fri Jan 05, 2007 4:48 am
Posts: 2
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
100WebSpace © 2011