Re: why do this not create a database?
From: Paul Barfoot (Paul_at_theglobalfamily.fsworld.co.uk)
Date: 10/03/04
- Next message: Paul Barfoot: "Re: require with $_GET parameters"
- Previous message: Dicki Smits: "Re: why do this not create a database?"
- In reply to: Dicki Smits: "Re: why do this not create a database?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 3 Oct 2004 13:22:59 +0100
Hi Dicki
Glad I could help!
As to closing the connection this is what the PHP help file says:
Using mysql_close() isn't usually necessary, as non-persistent open links
are automatically closed at the end of the script's execution.
You can get a copy of the help file from
http://www.php.net/download-docs.php
--
Paul Barfoot
"Dicki Smits" <dicki@absoluut.org> wrote in message
news:ac5e367f.0410022229.5a967a1a@posting.google.com...
> Paul thanks for your great help!!!
>
> i was wondering do i have to connect each time, now i learn it is not
> nesecary.
> But is it needed to close the connection?
> And how do i do that.
>
> Even your example learn me that you can do things on differend ways.
>
> Thanks....
> from holland
>
> "Paul Barfoot" <Paul@theglobalfamily.fsworld.co.uk> wrote in message
> news:<cjmjhf$jk$1@news5.svr.pol.co.uk>...
>> Hi Dicki
>>
>> Your code does create the table - it is your INSERT queries that are
>> wrong.
>> They should read INSERT INTO not INSERT TO.
>>
>> Here is my version of what you are trying to achieve with a few pointers:
>>
>> <html>
>> <title>hello world</title>
>>
>> <body>
>>
>> <?php
>>
>> $host = "localhost";
>> $user = "root";
>> $pswd = "";
>>
>> /* only need to connect and select database once */
>> mysql_connect($host,$user,$pswd) or die(mysql_error());
>> mysql_select_db ("project");
>>
>> /* code to delete the current version of the nieuws table */
>> mysql_query ("DROP TABLE IF EXISTS nieuws");
>>
>> /* Note date field should have used DATE type */
>> mysql_query ("CREATE TABLE IF NOT EXISTS nieuws ( id integer, title
>> varchar(255), date DATE, text blob)");
>>
>> /* Note format of DATE type - YYYY/MM/DD or even YYYY-MM-DD */
>> mysql_query ("INSERT INTO nieuws VALUES ( 1,'tweede
>> cursus','2004/05/05','een nieuwe cursus...')");
>>
>> mysql_query ("INSERT INTO nieuws VALUES (2,'tweede
>> cursus','2004/05/05','een
>> nieuwe cursus...')");
>>
>> $result = mysql_query("SELECT * FROM nieuws WHERE id=1");
>>
>> /* code to display the contents of the last query as a table with field
>> names as the table headers */
>> $results=mysql_num_rows($result);
>> if (!$results==0) {
>> echo "<p>$results rows returned.</p>\n";
>> echo "<table border=1>\n";
>> // get column metadata for column headings
>> echo "<tr>\n";
>> $i = 0;
>> while ($i < mysql_num_fields ($result)) {
>> $meta = mysql_fetch_field ($result);
>> if (!$meta) {
>> echo "No information available<BR>\n";
>> }
>> echo "<td><b>$meta->name</b></td>\n";
>> $i++;
>> }
>> echo "</tr>\n";
>> while ($row = mysql_fetch_row ($result)) {
>> echo "<tr>\n";
>> foreach ($row as $value) {
>> echo "<td>$value</td>\n";
>> }
>> echo "</tr>\n";
>> }
>> echo "</table>\n";
>> mysql_free_result ($result);
>> }
>> ?>
>> </body>
>> </html>
>>
>> --
>> Paul Barfoot
>>
>> "Dicki Smits" <dicki@absoluut.org> wrote in message
>> news:ac5e367f.0410012334.22168a19@posting.google.com...
>> >I am learning php-mysql but I typed the following into my notepad but
>> > it seems not to work. The page will be shown correct in the brouwser
>> > but it don't create a databse ????
>> >
>> > I use easyphp packet. php 4.3.3 ,mysql 4.0.15 . and apache 1.3.27
>> >
>> > any help would be great.
>> > greatings Dicki Smits
>> >
>> > ****
>> > <html>
>> > <title>hello world</title>
>> >
>> > <body>
>> >
>> > <?php
>> >
>> > $host = "localhost";
>> > $user = "root";
>> > $pswd = "";
>> >
>> > mysql_connect($host,$user,$pswd) or die(mysql_error());
>> > mysql_select_db ("fotoboek");
>> > mysql_query ("create table nie1uws ( id integer,
>> > title varchar(255),
>> > date integer,
>> > text blob)");
>> >
>> > mysql_connect($host,$user,$pswd) or die(mysql_error());
>> > mysql_select_db ("fotoboek");
>> > mysql_query ("INSERT TO nieuws values ( 1,
>> > 'tweede cursus',
>> > 5/5/2004,
>> > 'een nieuwe cursus...')");
>> >
>> > mysql_query ("INSERT TO nieuws values (2,'tweede
>> > cursus',5/5/2004,'een nieuwe cursus...')");
>> > mysql_connect($host,$user,$pswd) or die(mysql_error());
>> > mysql_select_db ("fotoboek");
>> > $result = mysql_query("select * from nieuws where id=1");
>> > echo $result
>> >
>> > ?>
>> > Waarom zie ik niet dat er geen database is aangemaakt?
>> > </body>
>> > </html>
- Next message: Paul Barfoot: "Re: require with $_GET parameters"
- Previous message: Dicki Smits: "Re: why do this not create a database?"
- In reply to: Dicki Smits: "Re: why do this not create a database?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]