Re: catch the error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2009-02-26 at 13:16 -0500, PJ wrote:
> Ashley Sheridan wrote:
> > On Thu, 2009-02-26 at 12:28 -0500, PJ wrote:
> >> What is wrond with this file? same identical insert works from console
> >> but not from this file :-(
> >>
> >> <html>
> >> <head>
> >> <title>Untitled</title>
> >> </head>
> >>
> >> <body>
> >> <?
> >> //include ("lib/db1.php"); // Connect to database
> >> mysql_connect('biggie', 'user', 'password', 'test');
> >> $sql1 = "INSERT INTO example (name, age) VALUES ('Joe Blow', '69')";
> >> $result1 = mysql_query($sql1,$db);
> >> if (!$result1) {
> >> echo("<P>Error performing 1st query: " .
> >> mysql_error() . "</P>");
> >> exit();
> >> }
> >> ?>
> >>
> >> </body>
> >> </html>
> >>
> >> Seems to be good to print out the error message, but that's all. db not
> >> written.
> >>
> >> -- 
> >>
> >> Phil Jourdan --- pj@xxxxxxxxxxxxx
> >> http://www.ptahhotep.com
> >> http://www.chiccantine.com
> >>
> >>
> > I'd say it was the way you are trying to connect to your database. This
> > is how it's done:
> >
> > $db_host = 'localhost';
> > $db_user = 'root';
> > $db_password = '';
> > $db_name = 'database_name';
> >
> > $db_connect = mysql_connect($db_host, $db_user, $db_pass);
> > $db_select = mysql_select_db($db_name, $db_connect);
> >
> > You see, first you have to cerate a connection to the database server,
> > then you have to select your database on that connection. In your
> > example, 'biggie' is the name of a server where your database resides,
> > and 'test', well, what can I say? This 4th parameter should be a boolean
> > indicating whether or not a new connection should be made upon
> > successive calls to mysql_connect.
> >
> >
> > Ash
> > www.ashleysheridan.co.uk
> >
> >
> OK, I see my error...understood and fixed... but it still does not work.
> But I did have an error - the include was wrong - missing ../
> Something is till amiss... the include configuration works, this does not?
> Why?
> 
> <?
> //include ("../lib/db1.php");    // Connect to database
> 
> $db_host = 'biggie';
> $db_user = 'myuser';
> $db_pass = 'my_pwd';
> $db_name = 'biblane';
> 
> $db_connect = mysql_connect($db_host, $db_user, $db_pass);
> $db_select = mysql_select_db($db_name, $db_connect);
> 
> $sql1 = "INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75')";
> $result1 = mysql_query($sql1,$db);
> if (!$result1) {
>   echo("<P>Error performing 1st query: " .
>        mysql_error() . "</P>");
>   exit();
> }
> ?>
> -- 
> 
> Phil Jourdan --- pj@xxxxxxxxxxxxx
> http://www.ptahhotep.com
> http://www.chiccantine.com
> 
OK, I wouldn't recommend this for a live server, but for development
it's fine; add in an or die('message') part to both the connect and
select lines and see what is displayed.


Ash
www.ashleysheridan.co.uk


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux