RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Tommy Pham
> -Original Message-
> From: Steve Staples [mailto:sstap...@mnsi.net]
> Sent: Tuesday, October 19, 2010 11:51 AM
> To: php-general
> Subject: RE: [PHP] Questions from a Newbie - Please Help
> 
> On Tue, 2010-10-19 at 11:18 -0700, Tommy Pham wrote:
> > > -Original Message-
> > > From: Steve Staples [mailto:sstap...@mnsi.net]
> > > Sent: Tuesday, October 19, 2010 11:07 AM
> > > To: Ethan Rosenberg
> > > Cc: php-general@lists.php.net
> > > Subject: RE: [PHP] Questions from a Newbie - Please Help
> > >
> > > 
> > >
> > > i am pretty sure i read it on here already...  but your PHP code looks
> wrong.
> > >
> > >
> > > ORIGNAL CODE:
> > > /*
> > >   *  Create Database test22
> > >   */
> > >   
> > >  > > $cxn = mysqli_connect("$host",$user,$password);
> > > echo"Create database test22;"
> > > echo"Create table Names2
> > > (
> > >  RecordNum Int(11) Primary Key Not null default=1
> auto_increment,
> > >  FirstName varchar(10),
> > >  LastName varchar(10),
> > >  Height  decimal(4,1),
> > >  Weight0 decimal(4,1),
> > >  BMI decimal(3,1)
> > >  Date0 date
> > > );"
> > >
> > > echo"   Create table Visit2
> > > (
> > >  Indx Int(7) Primary Key Not null auto_increment,
> > >  Weight decimal(4,1) not null,
> > >  StudyDate date not null,
> > >  RecordNum Int(11)
> > > );"
> > >
> > >  $sql= "SHOW DATABASES";
> > > ?>
> > > 
> > >
> > > FIXED CODE:
> > >
> > >   
> > >  > > /*
> > >   *  Create Database test22
> > >   */
> > > $cxn = mysqli_connect("$host",$user,$password);
> > > echo"Create database test22";
> > > echo"Create table Names2
> > > (
> > >  RecordNum Int(11) Primary Key Not null default=1
> auto_increment,
> > >  FirstName varchar(10),
> > >  LastName varchar(10),
> > >  Height  decimal(4,1),
> > >  Weight0 decimal(4,1),
> > >  BMI decimal(3,1)
> > >  Date0 date
> > > );";
> > >
> > > echo"Create table Visit2
> > > (
> > >  Indx Int(7) Primary Key Not null auto_increment,
> > >  Weight decimal(4,1) not null,
> > >  StudyDate date not null,
> > >  RecordNum Int(11)
> > > );";
> > >
> > >  $sql= "SHOW DATABASES";
> > > ?>
> > > 
> > >
> > > END FIXX
> > >
> > > firstly... you are missing your ending ; AFTER the " on most of your 
> > > lines...
> > > and i've seen this before, where it wont throw the error.
> > >
> > > secondly, all this is doing, is echoing out lines to either the
> > > console, or the web page... it is not running the queries at all.
> > > So, if you're trying to execute this from a shell script, then the
> > > line starting with $cxn that created the connection to the database, is
> irrelevant.
> > >
> > > If you are trying to just run from the website, and show what you
> > > WANT to do, then you have to end your statements with the ;
> > > character.  You should be able to copy and paste my "FIXED" code,
> > > and it should echo out something... it is helps, before you make the
> > > $cnx call, put in error_reporting(E_ALL);
> > >
> > > lastly,  if you want to call the queries from php, then you will
> > > have to remove the echo, and make them function calls to the
> database...
> > >
> > > here is a VERY quick redo of your code to make the mysqli calls:
> > >
> > >
> > >   
> > >  > > /*
> > >   *  Create Database test22
> > >   */
> > > $cxn = mysqli_connect("$host",$user,$password);
> > > echo"Create database test22";
> >
> > The 2 statements below would fail ;)
> 
> ACUTALLY... the only reason they fail, is becuase i didn't realize that I kept
> the other echo above, and it didn't create the database... that should have
> been:
> mysqli_query($cxn, "Create database test22");
> 
> and then

RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Steve Staples
On Tue, 2010-10-19 at 11:18 -0700, Tommy Pham wrote:
> > -Original Message-
> > From: Steve Staples [mailto:sstap...@mnsi.net]
> > Sent: Tuesday, October 19, 2010 11:07 AM
> > To: Ethan Rosenberg
> > Cc: php-general@lists.php.net
> > Subject: RE: [PHP] Questions from a Newbie - Please Help
> > 
> > 
> > 
> > i am pretty sure i read it on here already...  but your PHP code looks 
> > wrong.
> > 
> > 
> > ORIGNAL CODE:
> > /*
> >   *  Create Database test22
> >   */
> >   
> >  > $cxn = mysqli_connect("$host",$user,$password);
> > echo"Create database test22;"
> > echo"Create table Names2
> > (
> >  RecordNum Int(11) Primary Key Not null default=1 
> > auto_increment,
> >  FirstName varchar(10),
> >  LastName varchar(10),
> >  Height  decimal(4,1),
> >  Weight0 decimal(4,1),
> >  BMI decimal(3,1)
> >  Date0 date
> > );"
> > 
> > echo"   Create table Visit2
> > (
> >  Indx Int(7) Primary Key Not null auto_increment,
> >  Weight decimal(4,1) not null,
> >  StudyDate date not null,
> >  RecordNum Int(11)
> > );"
> > 
> >  $sql= "SHOW DATABASES";
> > ?>
> > 
> > 
> > FIXED CODE:
> > 
> >   
> >  > /*
> >   *  Create Database test22
> >   */
> > $cxn = mysqli_connect("$host",$user,$password);
> > echo"Create database test22";
> > echo"Create table Names2
> > (
> >  RecordNum Int(11) Primary Key Not null default=1 
> > auto_increment,
> >  FirstName varchar(10),
> >  LastName varchar(10),
> >  Height  decimal(4,1),
> >  Weight0 decimal(4,1),
> >  BMI decimal(3,1)
> >  Date0 date
> > );";
> > 
> > echo"Create table Visit2
> > (
> >  Indx Int(7) Primary Key Not null auto_increment,
> >  Weight decimal(4,1) not null,
> >  StudyDate date not null,
> >  RecordNum Int(11)
> > );";
> > 
> >  $sql= "SHOW DATABASES";
> > ?>
> > 
> > 
> > END FIXX
> > 
> > firstly... you are missing your ending ; AFTER the " on most of your 
> > lines...
> > and i've seen this before, where it wont throw the error.
> > 
> > secondly, all this is doing, is echoing out lines to either the console, or 
> > the
> > web page... it is not running the queries at all.  So, if you're trying to 
> > execute
> > this from a shell script, then the line starting with $cxn that created the
> > connection to the database, is irrelevant.
> > 
> > If you are trying to just run from the website, and show what you WANT to
> > do, then you have to end your statements with the ; character.  You should
> > be able to copy and paste my "FIXED" code, and it should echo out
> > something... it is helps, before you make the $cnx call, put in
> > error_reporting(E_ALL);
> > 
> > lastly,  if you want to call the queries from php, then you will have to
> > remove the echo, and make them function calls to the database...
> > 
> > here is a VERY quick redo of your code to make the mysqli calls:
> > 
> > 
> >   
> >  > /*
> >   *  Create Database test22
> >   */
> > $cxn = mysqli_connect("$host",$user,$password);
> > echo"Create database test22";
> 
> The 2 statements below would fail ;)

ACUTALLY... the only reason they fail, is becuase i didn't realize that
I kept the other echo above, and it didn't create the database... that
should have been:
mysqli_query($cxn, "Create database test22");

and then inside, creating the table "Names2" needs to be "test22.Names2"
and the same for "visit2".

the other issue, is with the create Names2... where the primary key is
default=1000 (should be default 1000), and auto_increment... can't have
a default AND auto_increment.

other than those, this works fine...  providing he has the $user, $host,
$password declared as well.

I personally dont use this, i use the PEAR:MDB2 classes, so this was
just a quick php.net search... WHICH would have helped the OP on this
one.

http://ca.php.net/manual/en/mysqli.query.php

I hate to say it, since i was a noob once, but RTFM, or LRN2GOOGLE and
you will find it easier, and then once you can't understand it, ask.
but

RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Tommy Pham
> -Original Message-
> From: Steve Staples [mailto:sstap...@mnsi.net]
> Sent: Tuesday, October 19, 2010 11:07 AM
> To: Ethan Rosenberg
> Cc: php-general@lists.php.net
> Subject: RE: [PHP] Questions from a Newbie - Please Help
> 
> 
> 
> i am pretty sure i read it on here already...  but your PHP code looks wrong.
> 
> 
> ORIGNAL CODE:
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22;"
> echo"Create table Names2
> (
>  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"
> 
> echo"   Create table Visit2
> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"
> 
>  $sql= "SHOW DATABASES";
> ?>
> 
> 
> FIXED CODE:
> 
>   
>  /*
>   *  Create Database test22
>   */
> $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22";
> echo"Create table Names2
> (
>  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );";
> 
> echo"Create table Visit2
> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );";
> 
>  $sql= "SHOW DATABASES";
> ?>
> 
> 
> END FIXX
> 
> firstly... you are missing your ending ; AFTER the " on most of your lines...
> and i've seen this before, where it wont throw the error.
> 
> secondly, all this is doing, is echoing out lines to either the console, or 
> the
> web page... it is not running the queries at all.  So, if you're trying to 
> execute
> this from a shell script, then the line starting with $cxn that created the
> connection to the database, is irrelevant.
> 
> If you are trying to just run from the website, and show what you WANT to
> do, then you have to end your statements with the ; character.  You should
> be able to copy and paste my "FIXED" code, and it should echo out
> something... it is helps, before you make the $cnx call, put in
> error_reporting(E_ALL);
> 
> lastly,  if you want to call the queries from php, then you will have to
> remove the echo, and make them function calls to the database...
> 
> here is a VERY quick redo of your code to make the mysqli calls:
> 
> 
>   
>  /*
>   *  Create Database test22
>   */
> $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22";

The 2 statements below would fail ;)

> mysqli_query($cxn, "Create table Names2
> (
>  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );");
> 
> mysqli_query($cxn, "Create table Visit2
> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );");
> 
>  $sql= "SHOW DATABASES";
>   $result = mysqli_query($cxn, $sql);
>   echo '';
>   print_r($result);
>   echo '';
> ?>
> 
> 
> 
> GOOD LUCK!  and just to note, i dont guarantee that this code will work, i am
> only taking what you had, and adding a little more to it, and I didn't test it
> out...
> 
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Steve Staples


i am pretty sure i read it on here already...  but your PHP code looks
wrong.


ORIGNAL CODE:
/*
  *  Create Database test22
  */
  



FIXED CODE:

  



END FIXX

firstly... you are missing your ending ; AFTER the " on most of your
lines... and i've seen this before, where it wont throw the error.

secondly, all this is doing, is echoing out lines to either the console,
or the web page... it is not running the queries at all.  So, if you're
trying to execute this from a shell script, then the line starting with
$cxn that created the connection to the database, is irrelevant.

If you are trying to just run from the website, and show what you WANT
to do, then you have to end your statements with the ; character.  You
should be able to copy and paste my "FIXED" code, and it should echo out
something... it is helps, before you make the $cnx call, put in 
error_reporting(E_ALL);

lastly,  if you want to call the queries from php, then you will have to
remove the echo, and make them function calls to the database...

here is a VERY quick redo of your code to make the mysqli calls:


  
';
print_r($result);
echo '';
?>



GOOD LUCK!  and just to note, i dont guarantee that this code will work,
i am only taking what you had, and adding a little more to it, and I
didn't test it out... 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie

2010-10-19 Thread Tommy Pham
> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: Tuesday, October 19, 2010 9:19 AM
> To: Tommy Pham; php-general@lists.php.net
> Subject: RE: [PHP] Questions from a Newbie
> 
> Dear List -
> 
> The error log only exists if he configures it properly and the script has
error.
> IE: log_errors & error_log.
> 
> I already had done that prior to the post.  That came from the manual, the
> necessary section thereof which had been read.
> 
> Now what?
> 
> Ethan
> ++


Here's what I perceive your scenario to be:

1) Connect to DB:  success? If not, why not? Server problem? Network problem
if everything is not on the same box? Firewall issue? Account privilege?
2) Send query to DB: success?  If not, why not? Same questions as above...
Did something happened after a successful connection?
3) What do I do with the success of the query?  Check if it's as expected?
Store it somewhere for later use? Display the results in html/xml?

To achieve the above, you need to understand the fundamentals such as what a
variable is and the types of variables.  What control structures are
(conditions, loops, etc.)...  Did you read the all that I've mentioned?
Since you've mentioned reading the MySQL/MySQLi section was too much for you
to comprehend implies, to me, that you don't understand the fundamentals or
didn't read the sections from the official manual that are required to begin
working with PHP.

Here's the code from OP:

> /*
>  *  Create Database test22
>  */
>  
>  $cxn = mysqli_connect("$host",$user,$password);

See point 1 for above.

> echo"Create database test22;"

See point 2.  What's the difference between display it as text/html/xml and
assigning it to use? If to use, you need to understand the fundamentals of
SQL for the below statement, which is beyond the scope of this list.  What
database are you executing the below command for?  You wouldn't know that
unless you check the result.

> echo"Create table Names2
> (
>RecordNum Int(11) Primary Key Not null default=1
auto_increment,
>FirstName varchar(10),
>LastName varchar(10),
>Height  decimal(4,1),
>Weight0 decimal(4,1),
>BMI decimal(3,1)
>Date0 date
> );"
>

See point 2. The below statement is the same as statement above in the
process.

> echo"   Create table Visit2
> (
>Indx Int(7) Primary Key Not null auto_increment,
>Weight decimal(4,1) not null,
>StudyDate date not null,
>RecordNum Int(11)
> );"
>

See point 2.

>$sql= "SHOW DATABASES";

See point 2 & 3 for the above.

> ?>
> 

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Ethan Rosenberg

Dear List -

I've checked the php.ini file [again] and cannot find any errors.

I wrote a PHP script to open a non-existent data base, and receive no error.

At this point, I am out of options.

Let's all look at the code, and tell me 1]where the error is and 
2]any corrections or additions to the ini file.


For personal reasons, which I cannot explain in a public forum, I am 
under extreme pressure to learn PHP ASAP.


Thank you.

Ethan
+++

At 08:31 AM 10/19/2010, Tommy Pham wrote:

> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: Tuesday, October 19, 2010 12:05 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Questions from a Newbie
>
> Tamara -
>
> Thanks.
>
> No error_log.
>

The error log only exists if he configures it properly and the script has
error.  IE: log_errors & error_log.  Like I said, Ethan should start from
the beginning of the manual.  It covers the configuration of PHP in addition
to the fundamentals of PHP.

> This works ...
>
> 
> 
> 
>
> Ethan
> ++
> At 02:23 AM 10/19/2010, Tamara Temple wrote:
> >On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:
> >
> >>
> >>I've added the code you suggest, and I still get a blank screen.
> >>Should I be explicitly be using mysqli functions; eg mysqli_connect?
> >Odd you should still get a blank screen and nothing in the error_log...
> >
> >Does phpinfo() work?
> >
> >>Ethan
> >>
> >>At 11:00 PM 10/18/2010, you wrote:
> >>>Where do you set $host, $user and $password?
> >>>
> >>>You should add the following after the new mysqli statement:
> >>>
> >>>if ($mysqli->connect_error) {
> >>>die('Connect Error (' . $mysqli->connect_errno . ') '
> >>>. $mysqli->connect_error); }
> >>>
> >>>Tamara Temple
> >>>-- aka tamouse__
> >>><mailto:tam...@tamaratemple.com>tam...@tamaratemple.com
> >>>
> >>>
> >>>"May you never see a stranger's face in the mirror."
> >>>
> >>>On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:
> >>>
> >>>>At 05:37 PM 10/17/2010, Tamara Temple wrote:
> >>>>>gah, i botched that up.
> >>>>>
> >>>>>For the first part, you want the following:
> >>>>>
> >>>>>$cxn = new mysql($host, $user, $password);
> >>>>>$res = $cxn->query("create database test22:);
> >>>>>if (!$res) {
> >>>>>die("Failed to create database test22: " .
> >>>>> $cxn- >error());
> >>>>>}
> >>>>>
> >>>>>Then, reopen the connection with the new data base:
> >>>>>
> >>>>>$cxn = new mysql($host, $user, $password, "test22");
> >>>>>
> >>>>>Then the following code will work.
> >>>>>
> >>>>>
> >>>>>Tamara Temple
> >>>>>-- aka tamouse__
> >>>>><mailto:tam...@tamaratemple.com>tam...@tamaratemple.com
> >>>>>
> >>>>>
> >>>>>"May you never see a stranger's face in the mirror."
> >>>>>
> >>>>>On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:
> >>>>>
> >>>>>>
> >>>>>>On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:
> >>>>>>>At 01:41 AM 10/17/2010, Tommy Pham wrote:
> >>>>>>>> > I cannot get the following to work.  In my Firefox
> >>>>>>>> > [Iceweasel]
> >>>>>>>>browser, I
> >>>>>>>> > enter the following URL: [w/ the http]
> >>>>>>
> >>>>>>Whenever you get a blank screen running a php application, the
> >>>>>>place to look is the http server's error_log. This is frequently
> >>>>>>found in / var/log/httpd/error_log or /var/log/apache2/error_log.
> >>>>>>(If your system is hosted someplace else, it could very easily be
> >>>>>>in a different place). Typically you need root permission to read
> >>>>>>this file. Tail the file after you run your PHP script to see the
> >>>>>>most recent errors.
> >>>>>&

RE: [PHP] Questions from a Newbie

2010-10-19 Thread Ethan Rosenberg

Dear List -

The error log only exists if he configures it properly and the script has
error.  IE: log_errors & error_log.

I already had done that prior to the post.  That came from the 
manual, the necessary section thereof which had been read.


Now what?

Ethan
++
At 08:31 AM 10/19/2010, Tommy Pham wrote:

> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: Tuesday, October 19, 2010 12:05 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Questions from a Newbie
>
> Tamara -
>
> Thanks.
>
> No error_log.
>

The error log only exists if he configures it properly and the script has
error.  IE: log_errors & error_log.  Like I said, Ethan should start from
the beginning of the manual.  It covers the configuration of PHP in addition
to the fundamentals of PHP.

> This works ...
>
> 
> 
> 
>
> Ethan
> ++
> At 02:23 AM 10/19/2010, Tamara Temple wrote:
> >On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:
> >
> >>
> >>I've added the code you suggest, and I still get a blank screen.
> >>Should I be explicitly be using mysqli functions; eg mysqli_connect?
> >Odd you should still get a blank screen and nothing in the error_log...
> >
> >Does phpinfo() work?
> >
> >>Ethan
> >>
> >>At 11:00 PM 10/18/2010, you wrote:
> >>>Where do you set $host, $user and $password?
> >>>
> >>>You should add the following after the new mysqli statement:
> >>>
> >>>if ($mysqli->connect_error) {
> >>>die('Connect Error (' . $mysqli->connect_errno . ') '
> >>>. $mysqli->connect_error); }
> >>>
> >>>Tamara Temple
> >>>-- aka tamouse__
> >>><mailto:tam...@tamaratemple.com>tam...@tamaratemple.com
> >>>
> >>>
> >>>"May you never see a stranger's face in the mirror."
> >>>
> >>>On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:
> >>>
> >>>>At 05:37 PM 10/17/2010, Tamara Temple wrote:
> >>>>>gah, i botched that up.
> >>>>>
> >>>>>For the first part, you want the following:
> >>>>>
> >>>>>$cxn = new mysql($host, $user, $password);
> >>>>>$res = $cxn->query("create database test22:);
> >>>>>if (!$res) {
> >>>>>die("Failed to create database test22: " .
> >>>>> $cxn- >error());
> >>>>>}
> >>>>>
> >>>>>Then, reopen the connection with the new data base:
> >>>>>
> >>>>>$cxn = new mysql($host, $user, $password, "test22");
> >>>>>
> >>>>>Then the following code will work.
> >>>>>
> >>>>>
> >>>>>Tamara Temple
> >>>>>-- aka tamouse__
> >>>>><mailto:tam...@tamaratemple.com>tam...@tamaratemple.com
> >>>>>
> >>>>>
> >>>>>"May you never see a stranger's face in the mirror."
> >>>>>
> >>>>>On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:
> >>>>>
> >>>>>>
> >>>>>>On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:
> >>>>>>>At 01:41 AM 10/17/2010, Tommy Pham wrote:
> >>>>>>>> > I cannot get the following to work.  In my Firefox
> >>>>>>>> > [Iceweasel]
> >>>>>>>>browser, I
> >>>>>>>> > enter the following URL: [w/ the http]
> >>>>>>
> >>>>>>Whenever you get a blank screen running a php application, the
> >>>>>>place to look is the http server's error_log. This is frequently
> >>>>>>found in / var/log/httpd/error_log or /var/log/apache2/error_log.
> >>>>>>(If your system is hosted someplace else, it could very easily be
> >>>>>>in a different place). Typically you need root permission to read
> >>>>>>this file. Tail the file after you run your PHP script to see the
> >>>>>>most recent errors.
> >>>>>>
> >>>>>>>> > The code  contained in the file CreateNew.php is:
> >>>>>>>> >
> >>>>>>>> > /

RE: [PHP] Questions from a Newbie

2010-10-19 Thread Tommy Pham
> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: Tuesday, October 19, 2010 12:05 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Questions from a Newbie
> 
> Tamara -
> 
> Thanks.
> 
> No error_log.
> 

The error log only exists if he configures it properly and the script has
error.  IE: log_errors & error_log.  Like I said, Ethan should start from
the beginning of the manual.  It covers the configuration of PHP in addition
to the fundamentals of PHP.

> This works ...
> 
> 
> 
> 
> 
> Ethan
> ++
> At 02:23 AM 10/19/2010, Tamara Temple wrote:
> >On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:
> >
> >>
> >>I've added the code you suggest, and I still get a blank screen.
> >>Should I be explicitly be using mysqli functions; eg mysqli_connect?
> >Odd you should still get a blank screen and nothing in the error_log...
> >
> >Does phpinfo() work?
> >
> >>Ethan
> >>
> >>At 11:00 PM 10/18/2010, you wrote:
> >>>Where do you set $host, $user and $password?
> >>>
> >>>You should add the following after the new mysqli statement:
> >>>
> >>>if ($mysqli->connect_error) {
> >>>die('Connect Error (' . $mysqli->connect_errno . ') '
> >>>. $mysqli->connect_error); }
> >>>
> >>>Tamara Temple
> >>>-- aka tamouse__
> >>><mailto:tam...@tamaratemple.com>tam...@tamaratemple.com
> >>>
> >>>
> >>>"May you never see a stranger's face in the mirror."
> >>>
> >>>On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:
> >>>
> >>>>At 05:37 PM 10/17/2010, Tamara Temple wrote:
> >>>>>gah, i botched that up.
> >>>>>
> >>>>>For the first part, you want the following:
> >>>>>
> >>>>>$cxn = new mysql($host, $user, $password);
> >>>>>$res = $cxn->query("create database test22:);
> >>>>>if (!$res) {
> >>>>>die("Failed to create database test22: " .
> >>>>> $cxn- >error());
> >>>>>}
> >>>>>
> >>>>>Then, reopen the connection with the new data base:
> >>>>>
> >>>>>$cxn = new mysql($host, $user, $password, "test22");
> >>>>>
> >>>>>Then the following code will work.
> >>>>>
> >>>>>
> >>>>>Tamara Temple
> >>>>>-- aka tamouse__
> >>>>><mailto:tam...@tamaratemple.com>tam...@tamaratemple.com
> >>>>>
> >>>>>
> >>>>>"May you never see a stranger's face in the mirror."
> >>>>>
> >>>>>On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:
> >>>>>
> >>>>>>
> >>>>>>On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:
> >>>>>>>At 01:41 AM 10/17/2010, Tommy Pham wrote:
> >>>>>>>> > I cannot get the following to work.  In my Firefox
> >>>>>>>> > [Iceweasel]
> >>>>>>>>browser, I
> >>>>>>>> > enter the following URL: [w/ the http]
> >>>>>>
> >>>>>>Whenever you get a blank screen running a php application, the
> >>>>>>place to look is the http server's error_log. This is frequently
> >>>>>>found in / var/log/httpd/error_log or /var/log/apache2/error_log.
> >>>>>>(If your system is hosted someplace else, it could very easily be
> >>>>>>in a different place). Typically you need root permission to read
> >>>>>>this file. Tail the file after you run your PHP script to see the
> >>>>>>most recent errors.
> >>>>>>
> >>>>>>>> > The code  contained in the file CreateNew.php is:
> >>>>>>>> >
> >>>>>>>> > /*
> >>>>>>>> >   *  Create Database test22
> >>>>>>>> >   */
> >>>>>>>> >   
> >>>>>>>> >  >>>>>>>> > $cxn = mysqli_connect("$host",$user,$password);
> >

Re: [PHP] Questions from a Newbie

2010-10-19 Thread Ethan Rosenberg

Tamara -

Thanks.

No error_log.

This works ...





Ethan
++
At 02:23 AM 10/19/2010, Tamara Temple wrote:

On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:



I've added the code you suggest, and I still get a blank screen.
Should I be explicitly be using mysqli functions; eg mysqli_connect?

Odd you should still get a blank screen and nothing in the error_log...

Does phpinfo() work?


Ethan

At 11:00 PM 10/18/2010, you wrote:

Where do you set $host, $user and $password?

You should add the following after the new mysqli statement:

if ($mysqli->connect_error) {
   die('Connect Error (' . $mysqli->connect_errno . ') '
   . $mysqli->connect_error);
}

Tamara Temple
-- aka tamouse__
tam...@tamaratemple.com


"May you never see a stranger's face in the mirror."

On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:


At 05:37 PM 10/17/2010, Tamara Temple wrote:

gah, i botched that up.

For the first part, you want the following:

   $cxn = new mysql($host, $user, $password);
   $res = $cxn->query("create database test22:);
   if (!$res) {
   die("Failed to create database test22: " . 
$cxn- >error());

   }

Then, reopen the connection with the new data base:

   $cxn = new mysql($host, $user, $password, "test22");

Then the following code will work.


Tamara Temple
   -- aka tamouse__
tam...@tamaratemple.com


"May you never see a stranger's face in the mirror."

On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:



On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:

> I cannot get the following to work.  In my Firefox [Iceweasel]
browser, I
> enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the
place
to look is the http server's error_log. This is frequently found
in / var/log/httpd/error_log or /var/log/apache2/error_log. (If
your
system is hosted someplace else, it could very easily be in a
different place). Typically you need root permission to read this
file. Tail the file after you run your PHP script to see the most
recent errors.


> The code  contained in the file CreateNew.php is:
>
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);


Better to use the OO approach:

   $cxn = new mysqli($host, $user, $password);


> echo"Create database test22;"


Instead of echo statements (which would just echo the contents to
the output, i.e., your browser, you want to assign them to a
variable, such as:

  $sql = "create database test22; use test22";

Then you need to execute the sql statement:

   $res = $cxn->query($sql);
   if (!$res) {
   die("Could not create database test22: " . 
$cxn- >error());

   }


> echo"Create table Names2


   $sql = "create table Names2


> (
>  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"


 ; // to close off the php statement
   $res = $cxn->query($sql);
   if (!$res) {
   die("Could not create table Names2: " . $cxn- >error());
   }


>
> echo"   Create table Visit2


   $sql = "create table Visit2


> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"


   ; // again, to close off the php statement
   $res = $cxn->query($sql);
   if (!$res) {
   die("Could not create table Visit2: " . $cxn- >error());
   }


>
>  $sql= "SHOW DATABASES";


This doesn't work in a programmatic setting.

Terminate the database connection:

   $cxn->close();


> ?>
> 



> I would also like to be able to add data to a table, using
PHP,
which I
can do
> in MySQL as:
> load data infile '/home/ethan/Databases/tester21.dat.' replace
into table
> Names fields escaped by '\\' terminated by '\t'  lines
terminated by '\n'
;


That's a specific feature of the mysql program. You'd have to
write
something in php to be able to parse the file and insert the data.
There are examples all over the net. Then you would need to set up
sql insert or replace statements to actually get the data into the
data base using mysqli::query. There are numerous examples of this
as well.

Here's one example:

   $insertdata[] = "$column='" . 
$cxn- >real_escape_string($data[$j+ +]) . "'"; // this assumes the

column names in the tsv file match
the column names in your data base table exactly. It also assumes
that all your data are strings, not numerics.
   }
   $sql .= implode(",",$insertdata);
   $res = $cxn->query($sql);
   if (!res) die ("Erro

RE: [PHP] Questions from a Newbie

2010-10-18 Thread Tommy Pham
> -Original Message-
> From: Paul M Foster [mailto:pa...@quillandmouse.com]
> Sent: Sunday, October 17, 2010 9:46 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Questions from a Newbie
> 
> On Sun, Oct 17, 2010 at 01:00:44AM -0400, Ethan Rosenberg wrote:
> 
> > Dear List -
> >
> > Here are some questions, which I am sure are trivial, but I am a
> > newbie, and cannot find the answers online
> >
> > I cannot get the following to work.  In my Firefox [Iceweasel]
> > browser, I enter the following URL: [w/ the http]
> >
> >  localhost/CreateNew.php All I get is a blank browser screen.
> >
> > The code  contained in the file CreateNew.php is:
> >
> > /*
> >  *  Create Database test22
> >  */
> >  
> >  > $cxn = mysqli_connect("$host",$user,$password);
> > echo"Create database test22;"
> > echo"Create table Names2
> 
> There's no need to quote $host above. Why your echo statements aren't
> showing up possibly indicates the script is aborting before it gets to
them.
> 
> In situations like this, check the error logs if possible. If not, break
the
> problem down into even smaller chunks. Do your connect with MySQL and
> then test to see if the connection actually worked. According to the docs,
> mysqli_connect() should return an object representing the connection. So
> check that first:
> 
> if (!is_object($cxn))
>   echo "Not connected!";
> else
>   echo "Yep, it connected!";
> 
> > (
> > RecordNum Int(11) Primary Key Not null default=1
> auto_increment,
> > FirstName varchar(10),
> > LastName varchar(10),
> > Height  decimal(4,1),
> > Weight0 decimal(4,1),
> > BMI decimal(3,1)
> > Date0 date
> > );"
> >
> 
> As has been mentioned, you're simply echoing these to the page, not
> sending them to MySQL. That won't work. You have to feed your SQL
> statements to the mysqli_query() function. See the docs.
> 
> Also, let me strongly advise you against using upper-and-lower-case field
> names in your tables. Others will undoubtedly disagree, but I find this a
> maintenance nightmare in the long run. Note that in some SQL variants
> (maybe in MySQL as well; I don't recall), you must quote the field names
in
> queries to preserve their case and make the queries work.
> 
> > echo"   Create table Visit2
> > (
> > Indx Int(7) Primary Key Not null auto_increment,
> > Weight decimal(4,1) not null,
> > StudyDate date not null,
> > RecordNum Int(11)
> > );"
> >
> > $sql= "SHOW DATABASES";
> 
> As mentioned elsewhere, this statement won't work in a web context. It
> only works from the MySQL console interface. There are other ways to
> achieve this in a programming context, but they involve querying the MySQL
> meta-tables.
> 
> Also, to those recommending PHPMyAdmin, it ignores the OP's question,
> and doesn't help him/her learn anything. It is completely possible to do
> what he wants programmatically, and often is done that way while
installing
> various frameworks, etc. *You're* welcome to use PHPMyAdmin, but let the
> OP do it his/her way, and help them along if you can.
> 
> Paul
> 
> --
> Paul M. Foster
> 

I recommended phpMyAdmin because I thought that he wanted to manage the
database using PHP.  Anyway, he lacked the fundamental understanding of PHP
and wanted to get into more advanced stuff.  As for what he intends in OP,
the statements will work provided that the MySQL account has the proper
privileges to do so and if the MySQL server is configured with 'show
databases' enabled.  Either case, he won't know for sure if those statements
executed correctly unless he understood the PHP fundamentals and use
conditions to check the results of each individual statement execution.
That's why I recommended him to read the manual from the beginning to get
the fundamentals because reading that MySQL section in the manual was too
much for him.

Regards,
Tommy 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Paul M Foster
On Sun, Oct 17, 2010 at 01:00:44AM -0400, Ethan Rosenberg wrote:

> Dear List -
> 
> Here are some questions, which I am sure are trivial, but I am a
> newbie, and cannot find the answers online
> 
> I cannot get the following to work.  In my Firefox [Iceweasel]
> browser, I enter the following URL: [w/ the http]
> 
>  localhost/CreateNew.php All I get is a blank browser screen.
> 
> The code  contained in the file CreateNew.php is:
> 
> /*
>  *  Create Database test22
>  */
>  
>  $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22;"
> echo"Create table Names2

There's no need to quote $host above. Why your echo statements aren't
showing up possibly indicates the script is aborting before it gets to
them.

In situations like this, check the error logs if possible. If not, break
the problem down into even smaller chunks. Do your connect with MySQL
and then test to see if the connection actually worked. According to the
docs, mysqli_connect() should return an object representing the
connection. So check that first:

if (!is_object($cxn))
echo "Not connected!";
else
echo "Yep, it connected!";

> (
> RecordNum Int(11) Primary Key Not null default=1 auto_increment,
> FirstName varchar(10),
> LastName varchar(10),
> Height  decimal(4,1),
> Weight0 decimal(4,1),
> BMI decimal(3,1)
> Date0 date
> );"
> 

As has been mentioned, you're simply echoing these to the page, not
sending them to MySQL. That won't work. You have to feed your SQL
statements to the mysqli_query() function. See the docs.

Also, let me strongly advise you against using upper-and-lower-case
field names in your tables. Others will undoubtedly disagree, but I find
this a maintenance nightmare in the long run. Note that in some SQL
variants (maybe in MySQL as well; I don't recall), you must quote the
field names in queries to preserve their case and make the queries work.

> echo"   Create table Visit2
> (
> Indx Int(7) Primary Key Not null auto_increment,
> Weight decimal(4,1) not null,
> StudyDate date not null,
> RecordNum Int(11)
> );"
> 
> $sql= "SHOW DATABASES";

As mentioned elsewhere, this statement won't work in a web context. It
only works from the MySQL console interface. There are other ways to
achieve this in a programming context, but they involve querying the
MySQL meta-tables. 

Also, to those recommending PHPMyAdmin, it ignores the OP's question,
and doesn't help him/her learn anything. It is completely possible to do
what he wants programmatically, and often is done that way while
installing various frameworks, etc. *You're* welcome to use PHPMyAdmin,
but let the OP do it his/her way, and help them along if you can.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tommy Pham
On Sun, Oct 17, 2010 at 11:22 AM, Ethan Rosenberg  wrote:
>
>



>
> Tommy -
>
> Thanks.
>
> As I stated, I am a newbie.
>
> 1] I am trying to shorten the learning curve by asking some questions, which
> I understand are probably trivial.  A whole MySQLi list of functions at this
> point is to much for me.  I have to break the problem into manageable parts.
>
> 2] It has been my experience that using a GUI does not teach the whole
> subject.  Linux, which is the OS I use cannot be run from a GUI.
>
> In the code being discussed, I wish to create a database and add two tables.
>  I also note a MySQL statement that can be used to add data to an existing
> table, and wish to be able to execute this statement using PHP.
>
> So, therefore..
>
> Let us try to answer the following two(2) questions:
>
> a] What changes [other than moving the simicolons] have to be made to
> correct the code.

That's why I suggested you to read that section regarding the usage of
PHP's MySQL extension.  If you still have problems understanding that
section or if it's a bit too much, I strongly suggest you start
reading the manual from the beginning.  It's obvious you're not very
clear on the syntax of PHP and you jumped right into the middle of
accessing the database and try to manipulate the DB using PHP.

What you need to know is the fundamentals 1st: variable declarations
and assignments, types of variables, basic outputs (such as echo,
print, etc), conditions, loops, etc...  In the official manual, all of
that is covered up to Classes & Objects, not including.  Class &
Objects and there after are for more of PHP5+ and OOP.  When in doubt,
there is always the function reference.

>
> b] What books can you suggest to help w/ MySQL and PHP?  I already have the
> SQL, MySQL & PHP, and HTML books in the . for Dummies series.  I need
> something with a little more depth and detail.

If you intend to use PHP to access the a DBMS, you need to have a
strong grasp of fundamentals of SQL.  I mean that as beyond  a simple
select statement.  If you already have that and the fundamentals of
PHP, reading that MySQL section I mentioned should give you the
understanding you needed on how to use PHP to access and manipulate
the data from the DB.  One good way to learn to copy the sample codes
from the manual and run it on your development box.   Make some
changes to code after the 1st few runs to see if you're understanding
it correctly and that you should be getting the output from the code
change as you expected based on your understanding of the material you
just read.  Reading any books (hard copy or electronic version) are
good but you won't truly understand and remember how it works unless
you apply that knowledge ASAP, IMO.  Learning for me is reverse
engineering.  That's the fastest way I learn.

>
> Thanks to all for your excellent help.
>
> Ethan
> 
>  Using Debian(sid)
> 
>
>

Regards,
Tommy

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tamara Temple

gah, i botched that up.

For the first part, you want the following:

$cxn = new mysql($host, $user, $password);
$res = $cxn->query("create database test22:);
if (!$res) {
die("Failed to create database test22: " . $cxn->error());
}

Then, reopen the connection with the new data base:

$cxn = new mysql($host, $user, $password, "test22");

Then the following code will work.


Tamara Temple
-- aka tamouse__
tam...@tamaratemple.com


"May you never see a stranger's face in the mirror."

On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:



On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:
> I cannot get the following to work.  In my Firefox [Iceweasel]  
browser, I

> enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the place  
to look is the http server's error_log. This is frequently found in / 
var/log/httpd/error_log or /var/log/apache2/error_log. (If your  
system is hosted someplace else, it could very easily be in a  
different place). Typically you need root permission to read this  
file. Tail the file after you run your PHP script to see the most  
recent errors.



> The code  contained in the file CreateNew.php is:
>
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);


Better to use the OO approach:

$cxn = new mysqli($host, $user, $password);


> echo"Create database test22;"


Instead of echo statements (which would just echo the contents to  
the output, i.e., your browser, you want to assign them to a  
variable, such as:


   $sql = "create database test22; use test22";

Then you need to execute the sql statement:

$res = $cxn->query($sql);
if (!$res) {
die("Could not create database test22: " . $cxn->error());
}


> echo"Create table Names2


$sql = "create table Names2


> (
>  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"


  ; // to close off the php statement
$res = $cxn->query($sql);
if (!$res) {
die("Could not create table Names2: " . $cxn->error());
}


>
> echo"   Create table Visit2


$sql = "create table Visit2


> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"


; // again, to close off the php statement
$res = $cxn->query($sql);
if (!$res) {
die("Could not create table Visit2: " . $cxn->error());
}


>
>  $sql= "SHOW DATABASES";


This doesn't work in a programmatic setting.

Terminate the database connection:

$cxn->close();


> ?>
> 



> I would also like to be able to add data to a table, using PHP,  
which I

can do
> in MySQL as:
> load data infile '/home/ethan/Databases/tester21.dat.' replace  
into table
> Names fields escaped by '\\' terminated by '\t'  lines  
terminated by '\n'

;



That's a specific feature of the mysql program. You'd have to write  
something in php to be able to parse the file and insert the data.  
There are examples all over the net. Then you would need to set up  
sql insert or replace statements to actually get the data into the  
data base using mysqli::query. There are numerous examples of this  
as well.


Here's one example:

	$contents = file($filename); // returns the contents of the file  
into an array, one line of file per array


	$columns = explode("\t", $contents[0]); // get the column names  
from the first line of the file


$sql = "insert into $table set ";
for ($i=1; $i			$insertdata[] = "$column='" . $cxn->real_escape_string($data[$j+ 
+]) . "'"; // this assumes the column names in the tsv file match  
the column names in your data base table exactly. It also assumes  
that all your data are strings, not numerics.

}
$sql .= implode(",",$insertdata);
$res = $cxn->query($sql);
if (!res) die ("Error inserting data: " . $cxn->error());
}
?>
Imported data

Data just imported:



	$res = $cxn->query("select * from $table limit 1"); // get one row  
from table for generating column names

if (!res) die ("Query failed for table $table: " . $cxn->error());
$row = $res->fetch_assoc();
foreach ($row as $column => $value) {
echo "" . $column . "";
}
?>



query("select * from $table");
if (!res) die ("Query failed for table $table: " . $cxn->error());
while ($row = $res->fetch_assoc()) {
echo "";
foreach ($row as $column => $value) {

Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tamara Temple


On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:
> I cannot get the following to work.  In my Firefox [Iceweasel]  
browser, I

> enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the place  
to look is the http server's error_log. This is frequently found in / 
var/log/httpd/error_log or /var/log/apache2/error_log. (If your system  
is hosted someplace else, it could very easily be in a different  
place). Typically you need root permission to read this file. Tail the  
file after you run your PHP script to see the most recent errors.



> The code  contained in the file CreateNew.php is:
>
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);


Better to use the OO approach:

$cxn = new mysqli($host, $user, $password);


> echo"Create database test22;"


Instead of echo statements (which would just echo the contents to the  
output, i.e., your browser, you want to assign them to a variable,  
such as:


   $sql = "create database test22; use test22";

Then you need to execute the sql statement:

$res = $cxn->query($sql);
if (!$res) {
die("Could not create database test22: " . $cxn->error());
}


> echo"Create table Names2


$sql = "create table Names2


> (
>  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"


  ; // to close off the php statement
$res = $cxn->query($sql);
if (!$res) {
die("Could not create table Names2: " . $cxn->error());
}


>
> echo"   Create table Visit2


$sql = "create table Visit2


> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"


; // again, to close off the php statement
$res = $cxn->query($sql);
if (!$res) {
die("Could not create table Visit2: " . $cxn->error());
}


>
>  $sql= "SHOW DATABASES";


This doesn't work in a programmatic setting.

Terminate the database connection:

$cxn->close();


> ?>
> 



> I would also like to be able to add data to a table, using PHP,  
which I

can do
> in MySQL as:
> load data infile '/home/ethan/Databases/tester21.dat.' replace  
into table
> Names fields escaped by '\\' terminated by '\t'  lines terminated  
by '\n'

;



That's a specific feature of the mysql program. You'd have to write  
something in php to be able to parse the file and insert the data.  
There are examples all over the net. Then you would need to set up sql  
insert or replace statements to actually get the data into the data  
base using mysqli::query. There are numerous examples of this as well.


Here's one example:

	$contents = file($filename); // returns the contents of the file into  
an array, one line of file per array


	$columns = explode("\t", $contents[0]); // get the column names from  
the first line of the file


$sql = "insert into $table set ";
for ($i=1; $i			$insertdata[] = "$column='" . $cxn->real_escape_string($data[$j+ 
+]) . "'"; // this assumes the column names in the tsv file match the  
column names in your data base table exactly. It also assumes that all  
your data are strings, not numerics.

}
$sql .= implode(",",$insertdata);
$res = $cxn->query($sql);
if (!res) die ("Error inserting data: " . $cxn->error());
}
?>
Imported data

Data just imported:



	$res = $cxn->query("select * from $table limit 1"); // get one row  
from table for generating column names

if (!res) die ("Query failed for table $table: " . $cxn->error());
$row = $res->fetch_assoc();
foreach ($row as $column => $value) {
echo "" . $column . "";
}
?>



query("select * from $table");
if (!res) die ("Query failed for table $table: " . $cxn->error());
while ($row = $res->fetch_assoc()) {
echo "";
foreach ($row as $column => $value) {
echo "" . $value . "";
}
echo "\n";
}
?>








As I stated, I am a newbie.

1] I am trying to shorten the learning curve by asking some  
questions, which I understand are probably trivial.  A whole MySQLi  
list of functions at this point is to much for me.  I have to break  
the problem into manageable parts.


Important, most used mysqli functions:

Creating the database connection: $cxn = new mysqli( host, user,  
password, database );  (mysqli::__construct function)


Submitting queries: $result = $cxn->query( sql ); (my

Re: [PHP] Questions from a Newbie

2010-10-17 Thread a...@ashleysheridan.co.uk
Linux can be run as a GUI, using a window manager.

Aside from that, have a look at the manual pages on php.net, which give some 
good examples of how to use the various mysql functions.

Also, on your development machine, its a good idea to turn on errors, as it can 
indicate where these problems are. You can do this from the php.ini, look for 
display_errors.

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: "Ethan Rosenberg" 
Date: Sun, Oct 17, 2010 19:22
Subject: [PHP] Questions from a Newbie
To: "Tommy Pham" , 



At 01:41 AM 10/17/2010, Tommy Pham wrote:
> > -Original Message-
> > From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> > Sent: Saturday, October 16, 2010 10:01 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] Questions from a Newbie
> >
> > Dear List -
> >
> > Here are some questions, which I am sure are trivial, but I am a newbie,
>and
> > cannot find the answers online
> >
> > I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
> > enter the following URL: [w/ the http]
> >
> >   localhost/CreateNew.php All I get is a blank browser screen.
> >
> > The code  contained in the file CreateNew.php is:
> >
> > /*
> >   *  Create Database test22
> >   */
> >   
> >  > $cxn = mysqli_connect("$host",$user,$password);
> > echo"Create database test22;"
> > echo"Create table Names2
> > (
> >  RecordNum Int(11) Primary Key Not null default=1
>auto_increment,
> >  FirstName varchar(10),
> >  LastName varchar(10),
> >  Height  decimal(4,1),
> >  Weight0 decimal(4,1),
> >  BMI decimal(3,1)
> >  Date0 date
> > );"
> >
> > echo"   Create table Visit2
> > (
> >  Indx Int(7) Primary Key Not null auto_increment,
> >  Weight decimal(4,1) not null,
> >  StudyDate date not null,
> >  RecordNum Int(11)
> > );"
> >
> >  $sql= "SHOW DATABASES";
> > ?>
> > 
> >
> > If I search for test22 or Visit2, nothing is found.
> >
> > I would also like to be able to add data to a table, using PHP, which I
>can do
> > in MySQL as:
> > load data infile '/home/ethan/Databases/tester21.dat.' replace into table
> > Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
>;
> >
> > Thanks in advance.
> >
> > Ethan
> > ===
> > Using Debian(sid)
> >
>
>You're reinventing the wheel that's been rolling along very smoothly for a
>long time... Google 'phpmyadmin'.  Also, read this entire section [1].
>
>Regards,
>Tommy
>
>[1] http://www.php.net/manual/en/book.mysqli.php

Tommy -

Thanks.

As I stated, I am a newbie.

1] I am trying to shorten the learning curve by asking some 
questions, which I understand are probably trivial.  A whole MySQLi 
list of functions at this point is to much for me.  I have to break 
the problem into manageable parts.

2] It has been my experience that using a GUI does not teach the 
whole subject.  Linux, which is the OS I use cannot be run from a GUI.

In the code being discussed, I wish to create a database and add two 
tables.  I also note a MySQL statement that can be used to add data 
to an existing table, and wish to be able to execute this statement 
using PHP.

So, therefore..

Let us try to answer the following two(2) questions:

a] What changes [other than moving the simicolons] have to be made to 
correct the code.

b] What books can you suggest to help w/ MySQL and PHP?  I already 
have the SQL, MySQL & PHP, and HTML books in the . for Dummies 
series.  I need something with a little more depth and detail.

Thanks to all for your excellent help.

Ethan

  Using Debian(sid)
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie

2010-10-17 Thread Ethan Rosenberg



At 01:41 AM 10/17/2010, Tommy Pham wrote:

> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: Saturday, October 16, 2010 10:01 PM
> To: php-general@lists.php.net
> Subject: [PHP] Questions from a Newbie
>
> Dear List -
>
> Here are some questions, which I am sure are trivial, but I am a newbie,
and
> cannot find the answers online
>
> I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
> enter the following URL: [w/ the http]
>
>   localhost/CreateNew.php All I get is a blank browser screen.
>
> The code  contained in the file CreateNew.php is:
>
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22;"
> echo"Create table Names2
> (
>  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"
>
> echo"   Create table Visit2
> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"
>
>  $sql= "SHOW DATABASES";
> ?>
> 
>
> If I search for test22 or Visit2, nothing is found.
>
> I would also like to be able to add data to a table, using PHP, which I
can do
> in MySQL as:
> load data infile '/home/ethan/Databases/tester21.dat.' replace into table
> Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;
>
> Thanks in advance.
>
> Ethan
> ===
> Using Debian(sid)
>

You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php


Tommy -

Thanks.

As I stated, I am a newbie.

1] I am trying to shorten the learning curve by asking some 
questions, which I understand are probably trivial.  A whole MySQLi 
list of functions at this point is to much for me.  I have to break 
the problem into manageable parts.


2] It has been my experience that using a GUI does not teach the 
whole subject.  Linux, which is the OS I use cannot be run from a GUI.


In the code being discussed, I wish to create a database and add two 
tables.  I also note a MySQL statement that can be used to add data 
to an existing table, and wish to be able to execute this statement 
using PHP.


So, therefore..

Let us try to answer the following two(2) questions:

a] What changes [other than moving the simicolons] have to be made to 
correct the code.


b] What books can you suggest to help w/ MySQL and PHP?  I already 
have the SQL, MySQL & PHP, and HTML books in the . for Dummies 
series.  I need something with a little more depth and detail.


Thanks to all for your excellent help.

Ethan

 Using Debian(sid)
 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie

2010-10-17 Thread Tommy Pham
> -Original Message-
> From: Alexis [mailto:phplis...@antonakis.co.uk]
> Sent: Sunday, October 17, 2010 4:10 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Questions from a Newbie
> 
> Ethan,you have the end of line semi colons enclosed in double
> quotes..move them to the true end of line.
> 

Even if he does move the semicolons to outside the quote, it doesn't do what he 
intended as maintaining the database.  His code merely echo the SQL syntax for 
viewing and not actually executing the SQL syntax, which is what I think he 
intended.  In which case, he's better off using phpMyAdmin.

Regards,
Tommy

> On 17/10/10 04:45, Christian Heinrich wrote:
> > Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:
> >> Dear List -
> >>
> >> Here are some questions, which I am sure are trivial, but I am a
> >> newbie, and cannot find the answers online
> >>
> >> I cannot get the following to work.  In my Firefox [Iceweasel]
> >> browser, I enter the following URL: [w/ the http]
> >>
> >>localhost/CreateNew.php All I get is a blank browser screen.
> >>
> >> The code  contained in the file CreateNew.php is:
> >>
> >> /*
> >>*  Create Database test22
> >>*/
> >>
> >>  >> $cxn = mysqli_connect("$host",$user,$password);
> >> echo"Create database test22;"
> >> echo"Create table Names2
> >> (
> >>   RecordNum Int(11) Primary Key Not null default=1
> auto_increment,
> >>   FirstName varchar(10),
> >>   LastName varchar(10),
> >>   Height  decimal(4,1),
> >>   Weight0 decimal(4,1),
> >>   BMI decimal(3,1)
> >>   Date0 date
> >> );"
> >>
> >> echo"   Create table Visit2
> >> (
> >>   Indx Int(7) Primary Key Not null auto_increment,
> >>   Weight decimal(4,1) not null,
> >>   StudyDate date not null,
> >>   RecordNum Int(11)
> >> );"
> >>
> >>   $sql= "SHOW DATABASES";
> >> ?>
> >> 
> >>
> >> If I search for test22 or Visit2, nothing is found.
> >>
> >> I would also like to be able to add data to a table, using PHP, which
> >> I can do in MySQL as:
> >> load data infile '/home/ethan/Databases/tester21.dat.' replace into
> >> table Names fields escaped by '\\' terminated by '\t'  lines
> >> terminated by '\n' ;
> >>
> >> Thanks in advance.
> >>
> >> Ethan
> >> ===
> >> Using Debian(sid)
> >>
> >>
> >>
> >
> >
> > Hi,
> >
> > maybe you also want to take a look at PDO - http://php.net/pdo
> >
> > Regards
> > Christian
> >
> >
> 
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Christian Heinrich
Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:
> Dear List -
> 
> Here are some questions, which I am sure are trivial, but I am a 
> newbie, and cannot find the answers online
> 
> I cannot get the following to work.  In my Firefox [Iceweasel] 
> browser, I enter the following URL: [w/ the http]
> 
>   localhost/CreateNew.php All I get is a blank browser screen.
> 
> The code  contained in the file CreateNew.php is:
> 
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22;"
> echo"Create table Names2
> (
>  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"
> 
> echo"   Create table Visit2
> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"
> 
>  $sql= "SHOW DATABASES";
> ?>
> 
> 
> If I search for test22 or Visit2, nothing is found.
> 
> I would also like to be able to add data to a table, using PHP, which 
> I can do in MySQL as:
> load data infile '/home/ethan/Databases/tester21.dat.' replace into 
> table Names fields escaped by '\\' terminated by '\t'  lines 
> terminated by '\n' ;
> 
> Thanks in advance.
> 
> Ethan
> ===
> Using Debian(sid)  
> 
> 
> 


Hi,

maybe you also want to take a look at PDO - http://php.net/pdo

Regards
Christian


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Alexis
Ethan,you have the end of line semi colons enclosed in double 
quotes..move them to the true end of line.


On 17/10/10 04:45, Christian Heinrich wrote:

Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:

Dear List -

Here are some questions, which I am sure are trivial, but I am a
newbie, and cannot find the answers online

I cannot get the following to work.  In my Firefox [Iceweasel]
browser, I enter the following URL: [w/ the http]

   localhost/CreateNew.php All I get is a blank browser screen.

The code  contained in the file CreateNew.php is:

/*
   *  Create Database test22
   */
   



If I search for test22 or Visit2, nothing is found.

I would also like to be able to add data to a table, using PHP, which
I can do in MySQL as:
load data infile '/home/ethan/Databases/tester21.dat.' replace into
table Names fields escaped by '\\' terminated by '\t'  lines
terminated by '\n' ;

Thanks in advance.

Ethan
===
Using Debian(sid)






Hi,

maybe you also want to take a look at PDO - http://php.net/pdo

Regards
Christian




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie

2010-10-16 Thread Tommy Pham
> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: Saturday, October 16, 2010 10:01 PM
> To: php-general@lists.php.net
> Subject: [PHP] Questions from a Newbie
> 
> Dear List -
> 
> Here are some questions, which I am sure are trivial, but I am a newbie,
and
> cannot find the answers online
> 
> I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
> enter the following URL: [w/ the http]
> 
>   localhost/CreateNew.php All I get is a blank browser screen.
> 
> The code  contained in the file CreateNew.php is:
> 
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22;"
> echo"Create table Names2
> (
>  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"
> 
> echo"   Create table Visit2
> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"
> 
>  $sql= "SHOW DATABASES";
> ?>
> 
> 
> If I search for test22 or Visit2, nothing is found.
> 
> I would also like to be able to add data to a table, using PHP, which I
can do
> in MySQL as:
> load data infile '/home/ethan/Databases/tester21.dat.' replace into table
> Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;
> 
> Thanks in advance.
> 
> Ethan
> ===
> Using Debian(sid)
> 

You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php