|
Posted by Jon Slaughter on 05/11/07 19:33
"harvey" <harvey.zzz@blueyonzders.com> wrote in message
news:MPG.20aebae984edb64e98999d@news-text.blueyonder.co.uk...
> In article <1178903815.663966.110230@y80g2000hsf.googlegroups.com>,
> matt.farey@gmail.com says...
>> remember though that it's considered good practise not to have php
>> use root, give php too many permissions and it will only be time
>> before your hard work comes back to haunt you, instead get use
>> to creating the db using the mysql command line (or some helpful gui)
>> and then immediately create a new user which has rights over this
>> database, and plug that into the php scripts that use that db,
>> limiting potential for disaster.
>>
>>
>
> hmmm... I can see that this is likely to get very complicated very
> quickly.
>
> My difficlty is I am at the learning stage with PHP and mySQL but I'm
> doing this to try and automate the procedures for someone who knows even
> less than I do. I need it to create the database and tables and
> then update the tables for him from forms in his browser -
>
> I can do most of it but the PHP/Mysql is new to me as I said.
>
> I've bought the Samms PHP,MYsql and Apache - All in One book and am
> working through it to get this done but it tends to gloss over
> or even ignore the really important stuff such as that you just
> mentioned. I'm reasonably Linux oriented so most of it makes sense but
> where issues don't arise at all I can miss them. (I'm not at all
> impressed with most of the books I've seen I must admit but this one did
> seem the best)
>
> Do you have any advice for me on using PHP to create the database appart
> from not doing it? (I suspect he doesnt have root access on his web site
> either so I'm guessing he needs to use his own ISP provided access - he
> does have the mySQL admin package but not the skills to use it -)
>
> Is there anything I can do to limit the problems of creating the database
> in PHP? I really don't want to try and get him to do anything manually.
>
>
>
Its actually quite easy. I too haven't done much in it but I'm pretty much
able to do all basic database stuff I need to.
Essentially you first log into the database using a function, create a sql
query string(which is probably going to be the hardest part but it too is
quite simple once you get over the mental block), and then query the
database with another function.
for example, heres a query for my database to check some stuff
$query="DELETE FROM ips WHERE ip='".mysql_real_escape_string($RMADDR,
$ldblink)."';";
$result = queryldb($query, $ldblink);
function logonldb($database)
{
$user="login";
$password="password";
$link = mysql_connect('localhost', $user, $password);
if (!$link) { dberror("Connection Error!"); }
$db_selected = mysql_select_db($database, $link);
if (!$db_selected) { dberror("Database Error!"); }
return $link;
}
and I use loginldb to log into the database and return the link that is used
in the calls. You also have to log out with somethign like
function logoffldb($link)
{
mysql_close($link);
}
the query function is defined as
function queryldb($query, $link)
{
$result = mysql_query($query, $link);
return $result;
}
also, if you are to get a result then you want to convert the query call
into an array using something like the following
if ($result != false) { $row = mysql_fetch_assoc($result); if ($row ==
false) { unset($row);}} else unset($row);
My wrappers are kinda unnecessary but hopefully you can see how basic it is.
Its just a few function calls and a little bit of setup(query string and
result conversion).
Its much easier than I ever expected and was a relief.
Jon
[Back to original message]
|