Welcome! Log In Create A New Profile

Advanced

Task 6A-1

Posted by DotKhoza 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Task 6A-1
May 01, 2007 10:54AM
Done. No serious issues.

To connect to the MySQL Server, I had to define $link_id as follows:

$link_id = mysql_connect("localhost", "root", ""winking smiley;

where localhost is the server, and root is the connection username. I am not using a password on my testing server, hence the "" at the end.

Prior to this, I had $link_id = mysql_connect(); Which obviously did not give the desired results.

After using $link_id = mysql_connect("localhost", "root", ""winking smiley;, the connection was successful and I could list the databases and the tables.

Cool...

A Successful Nature Inspires Other People...
Re: Task 6A-1
May 01, 2007 05:53PM
Completed, had also the same problem as DotKhoza but after i putted in my username and password all worked smiling smiley SQL in PHP is not so difficult!
avatar
Mac
Re: Task 6A-1
May 02, 2007 03:52PM
$link_id = mysql_connect(); can be used when you have a user "nobody". Google for more info, but it is not recommended for security reasons. So no need to explain smiling smileyPoni is, for each databse you need to define a user and password, with appropriate rights as to what user can do or not do in the database. Tedious, but required. Of course, for purposes of this course you can just have one user which you associate with every database usinf the mysql database (user and db tables).
avatar Re: Task 6A-1
May 03, 2007 05:23AM
In my previous post I said "No serious issues". But I think it is a serious issue that you are able to see the contents of a database if you are able to connect to it (if you follow Task6A-1 &2).

I have read that "To connect to a remote server, just enter either the hostname (e.g. www.microsoft.com) or the IP address (e.g. 212.113.192.101) as the first parameter, and your data will be transparently sent over the Internet." (Souce:hudzilla.org/phpwiki/index.php)

I will test this later...

This sounds serious and emphasises the use of usernames and passwords in our databases.

We live in a country where every citizen's safety and security is a concern. It is , however, not much more of a concern than the security concerns in cyberspace. Fortunately cyberspace security is much more manageable and less dangerous to human lives as there is often a back-up...

Being able to list the records contained in a database surely made me think.

Safety goes a long way...

Cheers.

A Successful Nature Inspires Other People...
Re: Task 6A-1
May 06, 2007 06:35PM
Really got involved with this one and had a great time. First time i have dealt with MySQL, as i am normally exposed to a bit of basic firebird.

I decided to make the database and table names hyperlinks, each revealing their contents on each click. Gave me a fill understanding of the tables. DotKhoza , try this code when u test your connection to a remote machine - it will reveal all !

<?php

$title = "Database Connection";
include ("header.php"winking smiley;

isset($_GET['db']) ? $db = ($_GET['db']) :$db = "none"; // echo $db;
isset($_GET['table']) ? $table = ($_GET['table']) :$table = "none"; // echo $table;

$mysqlserver = mysql_connect("localhost","root","12345"winking smiley;

if (!$mysqlserver)
die ("Oh well , it failed - the server says ".mysql_error() );

//---------------------------------------------------------------------------
// This will display the list of databases that are available :-

echo "<h3> The following databbases are avaialbe to this server</h3>";

$result = mysql_list_dbs();
while ($row = mysql_fetch_row($result))
{
echo "<a href=\"connect.php?db=$row[0] \">".$row[0]."</a><br>";
}
echo "<a href=connect.php>Collapse Thread</a>";

//----------------------------------------------------------------------------
// This will select the registration database and display all the tables :-

if ($db != "none"winking smiley
{
echo "<h3> The following tables are in the ".$db." database</h3>";

mysql_select_db($db);
$result = mysql_list_tables($db);
while($row = mysql_fetch_row($result))
{
echo "<a href=\"connect.php?db=$db&table=$row[0]\">".$row[0]."</a><br>";
}
echo "<a href=\"connect.php?db=$db\">Collapse Thread</a>";

//--------------------------------------------------------------------------
// This will show the table contents of the database :-

if ($table != "none"winking smiley
{
$result = mysql_query("SELECT count(*) from $table",$mysqlserver);
$count = mysql_fetch_row($result);
echo "<h3>",$count[0], " rows of data were found in the ", $table, " database</h3>";
if($count[0])
{
$result = mysql_query("SELECT * from $table",$mysqlserver);
while ($row = mysql_fetch_row($result))
{
print_r($row); echo "<br>"; //echo $row[0], "<br>";
}
}
else echo "The selected table is empty";
}
else
{
echo "<br><br> Click on a link above to reveal its field contents";
}
}
else
{
echo "<br><br> Click on a link above to reveal its table contents";
}
include ("footer.php"winking smiley;
?>


J

P.S - page is called connect.php - header.php & footer.php not included.
Re: Task 6A-1
May 07, 2007 11:31PM
Completed
avatar Re: Task 6A-1
May 08, 2007 04:26AM
Thanks, Jclamp.

Cheers

A Successful Nature Inspires Other People...
Re: Task 6A-1
May 08, 2007 09:16PM
Task Completeddrinking smiley
Re: Task 6A-1
May 09, 2007 03:21PM
Task completed. I used PhpMyAdmin to create a user studentphp and a password.

To connect to the MySQL Server, I had to define $link_id as $link_id = mysql_connect("localhost", "studentphp", "password"winking smiley and then it connected successfully.

I was thinking about security in terms of being able to access such a file that contains the connect parameters and reveals the login credentials. Is there a way other than securing the webserver that hosts the php files, to hide the code as would be the case with a compiled programming language. i.e. where the source is not revealed?
Re: Task 6A-1
May 09, 2007 07:36PM
Completed task, no problems.
Re: Task 6A-1
May 10, 2007 07:20PM
Task completed.

Query:

I found this bookstore_db folder, containing
subject.frm
subject.MYD
subject.MYI
titles.frm
titles.MYD
titles.MYI

What do I do with these? Please help. sad smiley
avatar
Mac
Re: Task 6A-1
May 11, 2007 07:54AM
Under the mysql folder, e.g. C:\\program files\xampp\mysql go to the data folder, create a folder bookstore, and copy these files into that folder. These are database information - when you create a database through phpMyAdmin (or any other tool, the information is stored here...
Re: Task 6A-1
May 11, 2007 10:55AM
Thank you! grinning smiley
Re: Task 6A-1
May 13, 2007 08:02PM
All Good.

Nino
Re: Task 6A-1
May 15, 2007 10:19AM
Completed successfully
Re: Task 6A-1
May 17, 2007 08:47PM
Done.
Re: Task 6A-1
May 29, 2007 09:38PM
Done
Re: Task 6A-1
June 01, 2007 03:32PM
Completed
Sorry, only registered users may post in this forum.

Click here to login